简体   繁体   English

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

[英]Difference in the output of git log --decorate: (HEAD -> master) vs (HEAD, master)

When I get the log of a GIT repo: 当我得到GIT仓库的日志时:

git log --oneline --decorate --graph

the output is like this: 输出是这样的:

* 44025ed (HEAD -> master) second commit
* adf2dbb first commmit

In another repo, when I git log , I get: 在另一个回购中,当我git log ,我得到:

* 435b61d (HEAD,master) bar
* 9773e52 foo

What is the difference between (HEAD -> master) and (HEAD,master) 有什么区别(HEAD -> master)(HEAD,master)

The arrow points to the current branch 箭头指向当前分支

An arrow to the right of HEAD , in the output of git log --oneline --decorate --graph , indicates which branch (if any) is the current one. HEAD右侧的箭头,在git log --oneline --decorate --graph的输出中,指示哪个分支(如果有)是当前分支。

* 44025ed (HEAD -> master) second commit

means that the symbolic reference HEAD currently points to the master branch; 表示符号引用HEAD当前指向master分支; in other words, you are not in detached-HEAD state, and the current branch is master . 换句话说,您处于detached-HEAD状态,并且当前分支是master

在此输入图像描述

In contrast, 相反,

* 44025ed (HEAD, master) second commit

means that the symbolic reference HEAD does not currently point to any branch, but to a commit ( 44025ed ) directly; 表示符号引用HEAD当前指向任何分支,而是直接指向提交( 44025ed ); in other words, you are in detached-HEAD state. 换句话说,你处于分离-HEAD状态。 The master branch is only listed alongside HEAD because it happens to point to the same commit ( 44025ed ). master分支仅与HEAD一起列出,因为它恰好指向相同的提交( 44025ed )。

在此输入图像描述

Some history 一些历史

For information, this distinction was introduced in Git (2.4) shortly after Can git log --decorate unambiguously tell me whether the HEAD is detached? 有关信息,这个区别是在Git(2.4)之后不久引入的.git log --decorate明确地告诉我HEAD是否已经分离? was asked on Stack Overflow. 被问到Stack Overflow。

A small experiment (to fix ideas) 一个小实验(修复想法)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM