Can git log --decorate unambiguously tell me whether the HEAD is detached?

坚强是说给别人听的谎言 提交于 2019-11-28 12:20:47

With Git 2.4+ (Q2 2015), git log --decorate will shows the exact branch associated with HEAD (or the lack thereof, for a detached HEAD).

See commit 51ff0f2 by Junio C Hamano (gitster):

log: decorate HEAD with branch name

Currently, log decorations do not indicate which branch is checked out and whether HEAD is detached.

When branch foo is checked out, change the "HEAD, foo" part of the decorations to "HEAD -> foo". This serves to indicate both ref decorations (helped by the spacing) as well as their relationshsip.

As a consequence, "HEAD" without any " -> " denotes a detached HEAD now.


This means the 2.4 release notes now include the following Backward compatibility warning(s):

Output from "git log --decorate" (and "%d" format specifier used in the userformat "--format=<string>" parameter "git log" family of command takes) used to list "HEAD" just like other tips of branch names, separated with a comma in between. E.g.

$ git log --decorate -1 master
commit bdb0f6788fa5e3cacc4315e9ff318a27b2676ff4 (HEAD, master)
...

This release updates the output slightly when HEAD refers to the tip of a branch whose name is also shown in the output.
The above is shown as:

$ git log --decorate -1 master
commit bdb0f6788fa5e3cacc4315e9ff318a27b2676ff4 (HEAD -> master)
...

Unfortunately, no. I keep wishing git log's --decorate used my HEAD= syntax. If it did, you would get:

4d860e9 (HEAD, master) Remove trailing whitespace
9a2ef02 Correct typo in header
f0badb5 Add to-do section to README

when you are carrying your head under your arm:

http://image.shutterstock.com/display_pic_with_logo/53755/53755,1189290972,1/stock-photo-a-beheaded-skeleton-carrying-a-glowing-pumpkin-head-under-his-arm-happy-halloween-isolated-on-5188306.jpg

but you would get this instead:

4d860e9 (HEAD=master) Remove trailing whitespace
9a2ef02 Correct typo in header
f0badb5 Add to-do section to README

when you are not in hallowe'en mode.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!