Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the 2nd column in the git reflog?

Tags:

git

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:

  • Column1 is obviously the commit,
  • Column2 is where I get confused. I understand the HEAD@{0} to HEAD@{7} concept. Don't get the parts that are in the parenthesis!. What does (yy, alphabets, hotFix) represent?
  • Column3 is the action i.e. checkout/pull along with a message.

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?

like image 225
mfaani Avatar asked Feb 05 '18 19:02

mfaani


People also ask

What is a Reflog in git?

Reflog is a mechanism to record when the tip of branches are updated. This command is to manage the information recorded in it. Basically every action you perform inside of Git where data is stored, you can find it inside of the reflog.

How do I see git Reflog?

git reflog directories can be found at . git/logs/refs/heads/. , . git/logs/HEAD , and also . git/logs/refs/stash if the git stash has been used on the repo.

What is branch Reflog?

a reflog is a very special “branch” that records each position of HEAD in the last 30 days (by default). So removed branches won't be purged by prune until after waiting for 30 days, when the last reference to them will finally be released. reflog history is not shared – it is exclusive to your repository.

What is difference between git log and Reflog?

The biggest difference between Git reflog vs. log is that the log is a public accounting of the repository's commit history while the reflog is a private, workspace-specific accounting of the repo's local commits. The Git log is part of the Git repository and is replicated after a push, fetch or pull.


1 Answers

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.

like image 195
Schwern Avatar answered Oct 24 '22 03:10

Schwern