git log输出的差异--decorate :( HEAD - > master)vs(HEAD,master)

时间:2016-05-20 10:50:07

标签: git git-log

当我得到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)

之间有何区别?

1 个答案:

答案 0 :(得分:10)

箭头指向当前分支

HEAD输出中git log --oneline --decorate --graph右侧的箭头表示当前分支(如果有)。

* 44025ed (HEAD -> master) second commit

表示符号引用HEAD当前指向master分支;换句话说,你处于分离-HEAD状态的,当前分支是master

enter image description here

相比之下,

* 44025ed (HEAD, master) second commit

表示符号引用HEAD当前指向任何分支,而是指向提交(44025ed);换句话说,你处于分离-HEAD状态。 master分支仅与HEAD一起列出,因为它恰好指向同一个提交(44025ed)。

enter image description here

一些历史

有关信息,这个区别是在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!
相关问题