달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

'GIT'에 해당되는 글 5건

  1. 2010.12.08 git commit 복구하기 3
  2. 2010.07.05 git reference
  3. 2010.04.27 git staic build
  4. 2010.04.23 git init --bare 이용 1
  5. 2010.04.23 git init --bare 발단

git commit 복구하기

Tool/git 2010. 12. 8. 01:26
git를 사용하면서 과감히 commit을 삭제할 때가 있는데, 때로는 이걸 복구해야 할 때가 있다.
git reset --hard 혹은 git branch -D 를 실수로 했을 때가 그 대표적 예일 것이다.

결론부터 얘기하면 git reset --hard에 대해서 다음과 같이 복구할 수 있고,
$ git reset --hard HEAD@{1}
git branch -D에 대해서 다음과 같이 복구할 수 있다.
$ git branch <new branch> HEAD@{1}
=> $ git branch mybranch HEAD@{1}

사실상 git branch -D 는 실행 직후 아래와 같은 log를 참고하여
Deleted branch temp (was c64b6d0).
아래와 같이 복구할 수도 있다.
$ git branch <new branch> <commit>
==> $ git branch mybranch c64b6d0

이는 git 내부에 소위 쓰레기통 같은 것이 있어서 사용자가 reference를 삭제하더라도
reflog에서 30일간 reference를 유지하여 git의 garbage collection으로부터 보호하기 때문이다.
reflog는 HEAD의 commit 이동을 기록하며, 아래와 같은 명령으로 이를 확인할 수 있다.
$ git reflog
HEAD@{#}에서 #는 HEAD가 #번 이전에 reference한 commit으로 HEAD@{1}가 직전이기 때문에 위와 같이 복구할 수가 있는 것이다.

위 내용은 아래 참고 문서에서 보고 따라한 것으로
아래 문서에서는 git reset --hard를 하기 전에 git stash를 통해 임시 저장하거나,
cron과 같은 것을 이용해서 자동으로 매일 git stash 하여 저장하는 것을 추천하고 있다.

참고 : Git from the bottom up - Git from the bottom up

'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 이용  (1) 2010.04.23
git init --bare 발단  (0) 2010.04.23
Posted by neodelicious
|

git reference

Tool/git 2010. 7. 5. 20:54
git user manual
http://www.kernel.org/pub/software/scm/git/docs/user-manual.html

git user manual 한글 번역본
http://namhyung.springnote.com/pages/3132772

git diagram 비롯한 사용법
http://osteele.com/archives/2008/05/my-git-workflow

git tutorial 1&2
http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html
http://www.kernel.org/pub/software/scm/git/docs/gittutorial-2.html

'Tool > git' 카테고리의 다른 글

git commit 복구하기  (3) 2010.12.08
git 알면 편한 기능  (0) 2010.11.13
git staic build  (0) 2010.04.27
git init --bare 이용  (1) 2010.04.23
git init --bare 발단  (0) 2010.04.23
Posted by neodelicious
|

git staic build

Tool/git 2010. 4. 27. 00:25
웹 호스팅 서비스를 통해서 개인 블로그를 사용하고 있는데,
여기에 개인용 git repository 를 두고 싶어졌다.

그런데 ssh로 접속해서 확인하니 git binary가 설치되어 있지 않았다.
그래서 아래와 같이 git binary를 직접 build 해서 이용하게 되었다.
이때 git binary에서 zlib과 pthread를 shared library로 이용하고 있어서,
관련 static library가 system에 설치되어 있어야 한다.

git binary를 위해 아래와 같이 소스를 다운로드 했다.
$ apt-get source git-core

그리고 Makefile을 열어 아래와 같이 ALL_LDFLAGS에 -static 옵션을 추가했다.
ALL_LDFLAGS = $(LDFLAGS) -static

다음과 같이 build 하고 build 디렉토리에 설치했다.
$ mkdir build
$ ./configure --prefix=/usr
$ make
$ make install DESTDIR=`pwd`/build

제대로 -static 하게 build 되었는지는 ldd git 와 같이 해서 확인할 수 있었다.
그리고 build/usr/bin 안의 git binary 들을 웹 호스팅 서버에 업로드하였다.

'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git init --bare 이용  (1) 2010.04.23
git init --bare 발단  (0) 2010.04.23
qgit  (0) 2010.04.20
Posted by neodelicious
|

git init --bare 이용

Tool/git 2010. 4. 23. 03:06
git repository에 소스가 있는데 이를 clone 해서 변경하고 push 하면 문제가 있다는 것을
이전 글에서 확인했다. (이전 글 --> http://www.neodelicious.com/entry/git-init-bare-1)

이번에는 --bare 옵션을 통해 위의 문제를 해결하는 방법을 설명하고자 한다.

글을 쓰기에 앞서 이전 글에서도 밝혔지만, 아래 웹 페이즈에서 많은 정보를 얻었음을 밝힌다.
http://stackoverflow.com/questions/738154/what-does-git-updating-currently-checked-out-branch-warning-mean

위 링크의 글 상단에 또 다른 링크 How to publish a Git repository를 출처로 bare repository 를 설명하고 있다.

이 bare repository 및 관련 내용을 간단히 번역하면,
우선 bare repository 는 git dababase 만 있고 소스 파일(working copy of code) 없는 것을 의미한다.
만약 bare repository가 아닌 소스 파일이 있는 git repository(non-bare repo)에 git push 하게 되면
HEAD가 git index, 소스 사이에  sync 문제가 발생하므로
(이게 이전 글 http://www.neodelicious.com/entry/git-init-bare-1 에서 확인한 사항이다.)
항상 bare repository에 git push 해야 한다.

그럼 위에서 권고한대로 우선 아무 것도 없는 디렉토리에서 git init --bare로 초기화해보자.
/.git 아래에 숨겨졌던 git database 파일들이 현재 디렉토리에 보이는 것을 확인했다.

jaewon@jaewon-laptop:~/work/study/tool/git$ mkdir remote_bare
jaewon@jaewon-laptop:~/work/study/tool/git$ cd remote_bare/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_bare$ git init --bare
Initialized empty Git repository in /home/jaewon/work/study/tool/git/remote_bare/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_bare$ ls
branches  config  description  HEAD  hooks  info  objects  refs

그 다음에 위의 bare repository를 git clone 하고 새 파일을 생성 및 수정하고 local에 git commit 했다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_bare$ cd ..
jaewon@jaewon-laptop:~/work/study/tool/git$ git clone ./remote_bare/ ./local
Initialized empty Git repository in /home/jaewon/work/study/tool/git/local/.git/
warning: You appear to have cloned an empty repository.
jaewon@jaewon-laptop:~/work/study/tool/git$ cd local/
jaewon@jaewon-laptop:~/work/study/tool/git/local$ echo "initial" > ./1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/local$ git add 1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/local$ git commit -a -m '1st'
[master (root-commit) 6833fa2] 1st
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 1.txt

그 다음에 bare repository에 git push를 하기 위해 git push 했는데,
다음과 같이 push의 기본 설정이 안 되어 있다고 해서 오류가 발생했다.

jaewon@jaewon-laptop:~/work/study/tool/git/local$ git push
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '/home/jaewon/work/study/tool/git/./remote_bare/'

여러 가지 설정이 있을 수 있겠지만, 나는 일단 tracking 방식을 기본으로 설정하고자
git config push.default tracking 과 같이 입력했다.
그리고 push를 정상적으로 할 수 있었다.

jaewon@jaewon-laptop:~/work/study/tool/git/local$ git config push.default tracking
jaewon@jaewon-laptop:~/work/study/tool/git/local$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /home/jaewon/work/study/tool/git/./remote_bare/
 * [new branch]      master -> master

참고적으로 소스 파일이 있는 git repository(non-bare repo)에 git push 해서 발생하는 문제는
이후 git 버전에서 금지될 것 이라고 한다.

또한 기존에 소스 파일이 있는 git repository(non-bare repo)을 clone 하려고 할 경우,
git clone --bare 와 같이 --bare 옵션을 주면 새 repo가 bare repo 가 된다.
git clone --bare 를 아래와 같이 확인했다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ cd ..
jaewon@jaewon-laptop:~/work/study/tool/git$ git clone --bare ./remote_src/ ./remote_src_bare
Initialized empty Git repository in /home/jaewon/work/study/tool/git/remote_src_bare/
jaewon@jaewon-laptop:~/work/study/tool/git$ cd remote_src_bare/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src_bare$ ls
branches  config  description  HEAD  hooks  info  objects  packed-refs  refs
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src_bare$ git log
commit 979521d7978f7a26c989047bae7806466353ad61
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:44:44 2010 +0900
    2nd
commit fc2d23fb93c972c3f48a75f9bf7be7de6a5d5ea3
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:42:48 2010 +0900
    initial

그런데 non-bare repo 에 push 하더라도 non-bare repo 의 code를 그대로 이용하지 않고
clone 한 후 pull 로 이용하면 문제가 없었다.
그래도 새로 만들 때는 bare 로 하는 게 좋겠다.

그밖에 Using Git to manage a web siteHow to publish a Git repository
hooks/post-receive 파일을 이용해서 git push 되면 자동으로 git checkout -f 되도록 하던데,
자세한 사항은 이해를 못 해서 지금은 넘어가기로 한다.


'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 발단  (0) 2010.04.23
qgit  (0) 2010.04.20
Posted by neodelicious
|

git init --bare 발단

Tool/git 2010. 4. 23. 01:37
git init --bare를 사용하게 된 배경을 설명하고 하며,
우선 간단하게 아래와 같이 문제 상황을 재현했다.

참고적으로 아래 웹 페이지에서 많은 정보를 얻었다.
http://stackoverflow.com/questions/738154/what-does-git-updating-currently-checked-out-branch-warning-mean


먼저 아래와 같이 1.txt 파일 하나가 들어 있는 디렉토리 remote_src 를 git server 로 초기화했다.

jaewon@jaewon-laptop:~/work/study/tool/git$ mkdir remote_src ; cd remote_src
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git init
Initialized empty Git repository in /home/jaewon/work/study/tool/git/remote_src/.git/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ touch 1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git add 1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git commit -a -m 'initial'
[master (root-commit) fc2d23f] initial
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 1.txt


그리고 다음과 같이 디렉토리 remote_src 의 git server 를 디렉토리 local_src 로 git clone 한 다음,
1.txt 파일을 수정하고 이를 local 에서 git commit 했다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git clone . ../local_src ; cd ../local_src
Initialized empty Git repository in /home/jaewon/work/study/tool/git/local_src/.git/
jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ echo "local modification" > ./1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ git commit -a -m '2nd'
[master 979521d] 2nd
 1 files changed, 1 insertions(+), 0 deletions(-)

그 다음 디레토리 remote_src 의 git server 로 소스 변경단을 반영하기 위해서 git push 했는데,
다음과 같은 경고 메시지를 확인했다.

jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ git push
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch
Counting objects: 5, done.
Writing objects: 100% (3/3), 250 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
warning: updating the current branch
warning: Updating the currently checked out branch may cause confusion,
warning: as the index and work tree do not reflect changes that are in HEAD.
warning: As a result, you may see the changes you just pushed into it
warning: reverted when you run 'git diff' over there, and you may want
warning: to run 'git reset --hard' before starting to work to recover.
warning:
warning: You can set 'receive.denyCurrentBranch' configuration variable to
warning: 'refuse' in the remote repository to forbid pushing into its
warning: current branch.
warning: To allow pushing into the current branch, you can set it to 'ignore';
warning: but this is not recommended unless you arranged to update its work
warning: tree to match what you pushed in some other way.
warning:
warning: To squelch this message, you can set it to 'warn'.
warning:
warning: Note that the default will change in a future version of git
warning: to refuse updating the current branch unless you have the
warning: configuration variable set to either 'ignore' or 'warn'.
To /home/jaewon/work/study/tool/git/remote_src/.
   fc2d23f..979521d  master -> master

위의 경고 메시지를 확인해 보니 정말 문제가 있었다.
우선 위의 경고 메시지는 2가지로서 하나는 현재 local 에서 어떤 branch 를 push 할 것이냐 하는 설정이고,
또 다른 하나는 현재 local의 branch로는 remote에 정상적으로 반영되어 보이지 않는다는 것이다.

먼저 remote에 반영 경고를 확인해 봤다.
아래처럼 local 과  remote 의 index에는 정상적으로 반영되었는데,

jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ git log
commit 979521d7978f7a26c989047bae7806466353ad61
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:44:44 2010 +0900
    2nd
commit fc2d23fb93c972c3f48a75f9bf7be7de6a5d5ea3
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:42:48 2010 +0900
    initial
jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ cd ../remote_src/ ; git log
commit 979521d7978f7a26c989047bae7806466353ad61
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:44:44 2010 +0900
    2nd
commit fc2d23fb93c972c3f48a75f9bf7be7de6a5d5ea3
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:42:48 2010 +0900
    initial

remote의 1.txt 파일과 git diff 정보에는 변경 사항이 반영되지 않았다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ cat ./1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git diff
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$

그런데 위의 경고 메시지처럼 git reset --hard 로써 현재 HEAD로 회기하였을 때 실제 1.txt 에 반영되었다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git reset --hard
HEAD is now at 979521d 2nd
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ cat ./1.txt
local modification

경고 메시지를 직접 확인했듯이,
remote_src 디렉토리의 소스 파일을 그대로 이용하는 것은 문제가 있다.
그럼 어떻게 해야 할 것인가?

'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 이용  (1) 2010.04.23
qgit  (0) 2010.04.20
Posted by neodelicious
|