본문 바로가기
IT 기술/개발환경_유틸 관련 팁

[git] git checkout 에서 '--' 의 의미

by 땅뚱 2012. 11. 6.

git help checkout 을 해보면 다음과 같은 SYNOPSIS 가 있다.

       git checkout [-q] [-f] [-m] [<branch>]
       git checkout [-q] [-f] [-m] [-b <new_branch>] [<start_point>]
       git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
       git checkout --patch [<tree-ish>] [--] [<paths>...]

여기서 [--] 은 무엇을 의미할까?

blog.avirtualhome.com/compile-mainline-kernel-ubuntu/ 의 creating a branch 섹션을 보면 다음과 같은 명령을 사용한다.

git checkout -b i7 v3.3 --

위에서 -- 는 무엇을 의미할까?? 구글링을 통해서 다음과 같은 사이트를 찾아내었다.

참고 : blog.avirtualhome.com/compile-mainline-kernel-ubuntu/


정리하면, -- 은 다른 옵션과 paths 를 구분하기 위한 구분자이다. 이러한 구분자가 존재하지 않는 경우라면, 다음의 명령들의 경우 여러가지로 해석될 가능성이 존재한다.

git checkout <tree-ish> <path1> <path2>
git checkout <path1> <path2> <path3>

하지만, -- 을 사용할 경우 명확해진다.

git checkout <tree-ish> -- <path1> <path2>
git checkout -- <path1> <path2> <path3>

즉 옵션으로 준 내용이 path 인지 git 내부의 tree-ish 인지를 구분해준다.

(tree-ish : revision tree 구조를 나타낸다. 디렉토리 구조가 아니다.

참고 : http://stackoverflow.com/questions/4044368/what-does-tree-ish-mean-in-git)

다시 git checkout 의 man page 를 확인해보자. EXAMPLES 섹션에 다음과 같은 예제가 있다.

$ git checkout master (1)
$ git checkout master~2 Makefile (2)
$ rm -f hello.c
$ git checkout hello.c (3)

(3) 의 경우에 이런 설명이 붙어 있다.

3. restore hello.c from the index

3. restore hello.c from the index

If you have an unfortunate branch that is named hello.c, this step would be confused as an instruction to switch to that branch.
You should instead write:

$ git checkout -- hello.c

즉 여기서도 마찬가지로 hello.c 가 tree-is 즉 branch name 인지, path 인지를 명확하게 해주기 위해서 -- 를 사용하여 구분한 것이다. 물론 hello.c 라는 branch name 이 없다면 혼동될 일은 없겠다.

결론적으로 아래 명령 의미는 v3.3 이 path(디렉토리 이름)가 아니라, tree-ish 즉 branch name 이란 것을 뜻한다.

git checkout -b i7 v3.3 --