I want list use git reflog format
, and show it as sorted by date with (--date=relative
) flag.
git reflog --format='%C(auto)%h %<|(17)%gd %C(blue)%cr%C(reset) %gs'
has following output:
$ git reflog --format='%C(auto)%h %<|(17)%gd %C(blue)%cr%C(reset) %gs'
cec94e5c HEAD@{0} 12 hours ago checkout: moving from 4ad171a16415754987475d38c0864278982f9d12 to dev
4ad171a1 HEAD@{1} 3 weeks ago checkout: moving from 9e0b5961ff88310b4ab41d90f34914f7b951ec69 to 4ad171a1
9e0b5961 HEAD@{2} 3 days ago checkout: moving from dev to 9e0b5961
cec94e5c HEAD@{3} 12 hours ago checkout: moving from 4ad171a16415754987475d38c0864278982f9d12 to dev
4ad171a1 HEAD@{4} 3 weeks ago checkout: moving from dev to 4ad171a1
cec94e5c HEAD@{5} 12 hours ago reset: moving to HEAD
cec94e5c HEAD@{6} 12 hours ago pull --rebase --autostash (finish): returning to refs/heads/dev
git reflog --date=relative
has following output:
$ git reflog --date=relative
cec94e5c (HEAD -> dev, origin/dev) HEAD@{3 seconds ago}: checkout: moving from 4ad171a16415754987475d38c0864278982f9d12 to dev
4ad171a1 HEAD@{11 hours ago}: checkout: moving from 9e0b5961ff88310b4ab41d90f34914f7b951ec69 to 4ad171a1
9e0b5961 HEAD@{11 hours ago}: checkout: moving from dev to 9e0b5961
cec94e5c (HEAD -> dev, origin/dev) HEAD@{11 hours ago}: checkout: moving from 4ad171a16415754987475d38c0864278982f9d12 to dev
4ad171a1 HEAD@{11 hours ago}: checkout: moving from dev to 4ad171a1
cec94e5c (HEAD -> dev, origin/dev) HEAD@{11 hours ago}: reset: moving to HEAD
cec94e5c (HEAD -> dev, origin/dev) HEAD@{11 hours ago}: pull --rebase --autostash (finish): returning to refs/heads/dev
Here when we use git reflog --date=relative
could we also show the HEAD@{<Number>}
corresponding to each item that matches to git commit hash.
Related: Is there a way to cause git-reflog to show a date alongside each entry?
@<number>
or@<date>
as the suffix for reflog entries. There's no format directive to force one or the other, only the options to globally set whether a date comes out and if so, whether it's relative. – Marelya@<date>
work when when there is same dates likeHEAD@{11 hours ago}
on my question ; since@<number>
is iterative there is not conflicting numbers – Faceplate{name}@{numeric suffix}
you'll seeHEAD@0
,HEAD@1
,HEAD@2
, etc. The numbers are always different. If the output format is{name}@{date suffix}
you'll seeHEAD
,HEAD@{11 hours ago}
, etc.; and if two dates are the same their suffix will be the same. – MarelyaHEAD@{11.hours.ago}
on a command line. In that case, Git picks one of them. Which one? You don't control that, so don't use that format. (The one Git picks is determined by the code, but unless you inspect the source carefully each time—it might change with each Git release—you can't know a priori which one that will be.) Since you have the hash ID to the left, use that instead. – Marelyagit switch br1; git switch br2; git switch br1
(and br1 differs from br2) thenHEAD
will contain the same hash ID asbr1
currently contains, andHEAD
's reflog will have it in there at least twice becauseHEAD
meant commita123456
at one point, then some other commit forbr2
at some point, then back toa123456
. – MarelyaHEAD
—is a way to refer to some particular commit. A branch name by definition holds the hash ID that is, we claim, the latest commit "on" that branch. Which commit is the latest? That depends on which one we want to be the latest, and that changes over time. So the reflog for a branch name contains different hash IDs over time. But sometimes we usegit reset
to move a name back, and then the same hash ID re-appears. – Marelya