달력

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 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
|