Last Updated: May 1, 2025
Reflog Basics
git reflogShow the local reflog — every HEAD movement recorded
git reflog show branchShow reflog for a specific branch
git reflog show --date=isoShow reflog with ISO timestamps
git reflog show --allShow reflog for all refs (HEAD, branches, stash)
git reflog show -10Show only the last 10 reflog entries
git reflog expire --expire=now --allClear 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
| Item | Description |
|---|---|
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-date | Show reflog with human-readable time offsets |
When to Use Reflog
| Item | Description |
|---|---|
After Bad Reset | Undo git reset --hard by checking out HEAD@{1} |
After Bad Rebase | Recover pre-rebase state from reflog |
After Branch Deletion | Restore deleted branch from its last reflog entry |
After Amend | Find original commit before git commit --amend |
After Squash | Recover individual commits lost during squash merge |
After Checkout | Return to previous branch without remembering its name |
Lost Commits | Any unreachable commit is findable via reflog for 90 days |
Audit Trail | Trace 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.