The preferred method is to use the simple syntax @{-1}
(thanks @phd).
git show --decorate -s @{-1}
Original answer:
The reflog does seem to keep a history of where HEAD
is moved, and looks to be accessible by the HEAD@{#}
variable.
This however does also include resets, rebases, cherry-picks, and commits. I assume that this is because all of those commands move the HEAD
.
104f63b (HEAD -> master, master.bak) HEAD@{0}: checkout: moving from b2 to master
e97431a (b2) HEAD@{1}: checkout: moving from b1 to b2
588aa76 (b1) HEAD@{2}: cherry-pick: C6
befdf09 HEAD@{3}: reset: moving to befdf09b
80cf3dd HEAD@{4}: checkout: moving from master to b1
104f63b (HEAD -> master, master.bak) HEAD@{5}: checkout: moving from b2 to master
e97431a (b2) HEAD@{6}: cherry-pick: C7
befdf09 HEAD@{7}: reset: moving to befdf09b
4dd1828 HEAD@{8}: checkout: moving from master to b2
104f63b (HEAD -> master, master.bak) HEAD@{9}: commit: C5
be1bfdb HEAD@{10}: commit: C4
07743f7 HEAD@{11}: commit: C3
befdf09 HEAD@{12}: checkout: moving from b1 to master
80cf3dd HEAD@{13}: commit: C6
4dd1828 HEAD@{14}: checkout: moving from b2 to b1
4dd1828 HEAD@{15}: commit: C7
befdf09 HEAD@{16}: checkout: moving from master to b2
befdf09 HEAD@{17}: commit: C2
464acc2 HEAD@{18}: commit (initial): C1
If checking the reflog is too much there is a program to help with that.