Can git log -decorate definitely tell me if HEAD is disconnected?

I know that in the Git expression, โ€œseparate HEADโ€ corresponds to a state in which the HEAD symbolic link does not point to any branch. I also know that git branch , for example, will tell me if I am in standached-HEAD state, for example

 * (detached from 9a2ef02) master 

or not, for example

 * master 

However, I would like to know if there is a way to make the output of git log --decorate completely unambiguous as to whether I am in standached-HEAD state or not. Here is an example explaining what I mean by "explicit."

enter image description here

Example

Let's say I'm on master , and my story is as follows:

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

Case 1: Unambiguous State of an Individual HEAD

If I run

 git checkout 9a2ef02 

then the output of git log --decorate --oneline is

 9a2ef02 (HEAD) Correct typo in header f0badb5 Add to-do section to README 

Since there is no branch link next to HEAD in this release, I know for sure that I have a separate head.

Case 2: disabled HEAD state or not?

However, if I run

 git checkout 4d860e9 

then HEAD does not point to master , but directly to commit 4d860e9 , which also points to master ; I have a separate HEAD. However, the output of git log --decorate --oneline ,

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

because it is exactly the same as when I am on master .

Is there a way, through some git log options, to remove this ambiguity? I did not find a way in the git-log man page ...

+6
source share
2 answers

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

See commit 51ff0f2 Junio โ€‹โ€‹C Hamano ( gitster ) :

log : decorate HEAD with branch name

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

When the branch foo , change the " HEAD, foo " part to decorations to " HEAD -> foo ". This serves to indicate both reflection (using the interval) and their relationships.

As a result, โ€œ HEAD โ€ without any โ€œ -> โ€ means disconnected HEAD now .


This means that release notes for 2.4 now include the following backward compatibility warnings :

The output from the format specifier " git log --decorate " (and " %d " used in the parameter userformat " --format=<string> " " git log "), which is used to enumerate " HEAD ", as well as other name hints branches separated by a comma between them. For instance.

 $ 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 also appears in the output.
The above is shown as:

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

[Edit: starting with Git 2.4, see VonC answer . The text below is for versions of Git prior to 2.4.]

Unfortunately not. I continue to wish that git log --decorate use my HEAD= syntax. If so, you will receive:

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

when you carry your head under your arm:


(source: shutterstock.com )

but you will 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.

+2
source

Source: https://habr.com/ru/post/974052/


All Articles