Git Reflog Cheat Sheet

Git reflog — your safety net for recovering lost commits, understanding HEAD@{n} references, and undoing almost anything in Git.

Last Updated: May 1, 2025

Reflog Basics

git reflog
Show the local reflog — every HEAD movement recorded
git reflog show branch
Show reflog for a specific branch
git reflog show --date=iso
Show reflog with ISO timestamps
git reflog show --all
Show reflog for all refs (HEAD, branches, stash)
git reflog show -10
Show only the last 10 reflog entries
git reflog expire --expire=now --all
Clear all reflogs (dangerous!)

Recovering Lost Work

git checkout HEAD@{2}
Check out where HEAD was 2 movements ago
git branch recovered HEAD@{3}
Create a branch at a lost commit position
git reset --hard HEAD@{1}
Undo a bad reset by going back one HEAD move
git cherry-pick HEAD@{5}
Recover a specific commit from reflog history
git merge HEAD@{yesterday}
Merge from where HEAD was yesterday
git show HEAD@{'10 minutes ago'}
Inspect where HEAD was 10 minutes ago

Understanding References

ItemDescription
HEAD@{0}Current HEAD position (same as HEAD)
HEAD@{1}Previous HEAD position (one move ago)
HEAD@{5.minutes.ago}Where HEAD was 5 minutes ago (time-based)
HEAD@{yesterday}Where HEAD was yesterday at this time
main@{1}Previous position of the main branch
main@{one.week.ago}Where main was one week ago
stash@{0}Most recent stash entry
git reflog --relative-dateShow reflog with human-readable time offsets

When to Use Reflog

ItemDescription
After Bad ResetUndo git reset --hard by checking out HEAD@{1}
After Bad RebaseRecover pre-rebase state from reflog
After Branch DeletionRestore deleted branch from its last reflog entry
After AmendFind original commit before git commit --amend
After SquashRecover individual commits lost during squash merge
After CheckoutReturn to previous branch without remembering its name
Lost CommitsAny unreachable commit is findable via reflog for 90 days
Audit TrailTrace exactly what commands were run in what order
Pro Tip: The reflog is local only and expires after 90 days. Push important recovered commits to a remote branch to preserve them permanently.