当我得到GIT仓库的日志时:
git log --oneline --decorate --graph
输出如下:
* 44025ed (HEAD -> master) second commit
* adf2dbb first commmit
在另一个回购中,当我git log
时,我得到:
* 435b61d (HEAD,master) bar
* 9773e52 foo
(HEAD -> master)
和(HEAD,master)
答案 0 :(得分:10)
HEAD
输出中git log --oneline --decorate --graph
右侧的箭头表示当前分支(如果有)。
* 44025ed (HEAD -> master) second commit
表示符号引用HEAD
当前指向master
分支;换句话说,你处于分离-HEAD状态的不,当前分支是master
。
相比之下,
* 44025ed (HEAD, master) second commit
表示符号引用HEAD
当前不指向任何分支,而是指向提交(44025ed
);换句话说,你处于分离-HEAD状态。 master
分支仅与HEAD
一起列出,因为它恰好指向同一个提交(44025ed
)。
有关信息,这个区别是在Stack Overflow上询问Can git log --decorate unambiguously tell me whether the HEAD is detached?后不久在Git(2.4)中引入的。
$ mkdir decorate-test
$ cd decorate-test/
$ git init
Initialized empty Git repository in /xxxxxxx/decorate-test/.git/
$ touch README
$ git add README
$ git commit -m "Add README"
[master (root-commit) 50781c9] Add README
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README
$ git log --oneline --decorate --graph
* 50781c9 (HEAD -> master) Add README
# Note the presence of the arrow in the output.
# Now, check out the commit directly to detach the HEAD:
$ git checkout 50781c9
Note: checking out '50781c9'.
You are in 'detached HEAD' state. You can look around, ...
HEAD is now at 50781c9... Add README
$ git log --oneline --decorate --graph
* 50781c9 (HEAD, master) Add README
# The arrow is gone!
# Check out master again to reattach the HEAD:
$ git checkout master
Switched to branch 'master'
$ git log --oneline --decorate --graph
* 50781c9 (HEAD -> master) Add README
# The arrow is back!