gitgit-reflog

What is the 2nd column in the git reflog?


I just did a simple git reflog and this is the first few lines I got:

column1                 Column2                                Column3
2797a1d4 (HEAD -> master, upstream/master) HEAD@{0}: checkout: moving from master to master
2797a1d4 (HEAD -> master, upstream/master) HEAD@{1}: pull upstream master: Fast-forward
a461a29f HEAD@{2}: checkout: moving from master to master
a461a29f HEAD@{3}: reset: moving to HEAD
a461a29f HEAD@{4}: pull upstream master: Fast-forward
784f2cp3 (yy, alphabets, hotFix) HEAD@{5}: checkout: moving from yy to master
784f2cp3 (yy, alphabets, hotFix) HEAD@{6}: checkout: moving from master to yy
784f2cp3 (yy, alphabets, hotFix) HEAD@{7}: checkout: moving from alphabets to master

I'm trying to understand what each column represents. Reading from this post and this question I've already learned:

Additionally I'm uncertain as to why there is multiple lines of the same commit? Is it because different branches are all pointing to the same commit and there is no code changes between them?


Solution

  • The reflog tells you how HEAD has moved. There are more than three columns. The Git docs are obtuse about this. It turns out git reflog is just an alias for git log with some switches.

    git reflog show [the default] is an alias for git log -g --abbrev-commit --pretty=oneline;

    784f2cp3 (yy, alphabets, hotFix) HEAD@{7}: checkout: moving from alphabets to master
    
    1. 784f2cp3 The abbreviated commit.
    2. (yy, alphabets, hotFix) The branch heads at this commit, just like git log --decorate.
    3. HEAD@{7} The location of this commit relative to HEAD, added by -g.
    4. checkout What command was run.
    5. moving from alphabets to master A human readable description.

    (4 and 5 are technically the same column.)

    This says you were on branch alphabets and ran git checkout master.

    Additionally I'm uncertain as to why there is multiple lines of the same commit? Is it because different branches are all pointing to the same commit and there is no code changes between them?

    Yes, exactly.

    784f2cp3 (yy, alphabets, hotFix) HEAD@{5}: checkout: moving from yy to master
    784f2cp3 (yy, alphabets, hotFix) HEAD@{6}: checkout: moving from master to yy
    784f2cp3 (yy, alphabets, hotFix) HEAD@{7}: checkout: moving from alphabets to master
    

    yy, alphabets, hotFix, and master were all on the same commit. Checking out between them simply changes which branch head will be moved the next commit.

    The others might be internal HEAD movements which happen when you run git pull. git pull is a combination of git fetch and git merge.