Search code examples
gitgit-log

Git log to show where exactly HEAD points?


Is there a way to make git log to show differently the situations where (a) HEAD points to branch pointer and branch pointer points to commit, and (b) HEAD points directly to commit, and also branch pointer points to the same commit?

For example, if I do

git commit -m'My commit'
git log --oneline --graph --decorate
* 655c6f1 (HEAD, master) My commit

So now the situation is: 655c6f1 <- master <- HEAD. But if I do

git checkout 655c6f1
git log --oneline --graph --decorate
* 655c6f1 (HEAD, master) My commit

So now the situation is: 655c6f1 <- master, 655c6f1 <- HEAD. (And I am in a detached HEAD state.)

But in both cases the git log output is identical. How to make git log differentiate between these two situations?


Solution

  • Git 2.4+ (April 2015) does show you a clear difference between HEAD branch and detached HEAD after checkout.
    See commit 51ff0f2.

    This is what you see when HEAD refers to a branch.

    C:\Users\vonc\prog\b2d>git log --oneline --graph --decorate -3
    * 8956c85 (HEAD -> master, origin/master) apache/(run/kill): runs/kills gnupg2 as well
    * 216834a gitolite/run: uses {fgrpath}/.init_envs.sh as a marker
    

    Note the HEAD -> master part.

    And when detaching the HEAD:

    C:\Users\vonc\prog\b2d>git log --oneline --graph --decorate -3
    * 8956c85 (HEAD, origin/master, master) apache/(run/kill): runs/kills gnupg2 as well
    * 216834a gitolite/run: uses {fgrpath}/.init_envs.sh as a marker
    

    Even Windows has Git 2.4+ now: PortableGit-2.5.0-64-bit.7z.exe.