git reflog: the log of HEAD movements
Updated July 31, 2026
git reflog lists every place HEAD has stood and keeps the hashes of commits that have already vanished from git log. It is the main safety net in git: while the hash is in the log, the commit can come back.
$ git reflog
024f79c HEAD@{0}: reset: moving to HEAD~1
ef4b778 HEAD@{1}: commit: a draft that went nowhere
024f79c HEAD@{2}: revert: Revert "fixed the typos"
fb4dceb HEAD@{3}: commit: fixed the typosRead it top to bottom, newest first. HEAD@{0} is where you stand now, HEAD@{1} is where you stood one step earlier. On the left is the commit hash, on the right the reason for the move: commit, checkout, merge, reset, revert. Git writes every movement of HEAD here on its own, without being asked.
That is where the safety net comes from. In the listing above, reset dropped commit ef4b778 and git log no longer shows it. The hash is still in the log, though, and a hash is enough to bring the commit back:
$ git reset --hard ef4b778 # move the branch back onto the lost commit
HEAD is now at ef4b778 a draft that went nowhere
$ git switch -c rescue ef4b778 # or pull it out into a branch of its own
Switched to a new branch 'rescue'A reference like HEAD@{2} works anywhere a hash works: git show HEAD@{2}, git diff HEAD@{5}. Every branch has a log of its own, and git reflog show main prints the movements of that branch only.
Two caveats. The reflog is local: it lives in your copy of the repository, not on the server and not in your colleague's clone. In a fresh clone the log holds a single line, clone: from ..., because the history of movements starts over. And entries do not last forever: by default they are kept for 90 days, and entries pointing at commits no branch can reach are dropped after 30.
Common mistakes
HEAD@{2} and HEAD~2 look alike and mean different things. The first is "where HEAD stood two steps ago in time", the second is "two commits back in the history". They rarely match: switching branches moves HEAD without going anywhere in the history.
The reflog holds pointer movements, not the content of your working directory. Edits that never reached a commit, the index or git stash are gone after git reset --hard, and nothing brings them back. Hence the advice to commit often: a small commit can always be folded into the next one, a commit that was never made cannot.
Where this is in the book
The reflog and the rescue of lost commits are covered in chapter 8.
Chapter 8. First aid: when something goes wrong
To practise it by hand, open the Sandbox: a real terminal with git and step checks.