How to Recover Lost Commits With git reflog
git reflog records every position HEAD has pointed to, letting you recover commits that seem lost after a reset, rebase, or branch deletion.
Published September 28, 2026
git reflog is a log of where HEAD and branch tips have pointed, including commits that are no longer on any branch. It lets you recover work after a bad reset, rebase or deleted branch.
How it works
Git keeps unreachable commits for weeks. Reflog entries like HEAD@{3} point to them so you can reset or branch from them.
Reflog is local only and expires, so recover promptly.
Try it
git reflog
a1b2c3d HEAD@{0}: reset: moving to HEAD~2
d4e5f6a HEAD@{1}: commit: Add search
Practical examples
Find and restore
git reflog
git reset --hard HEAD@{1}Recover a deleted branch
git branch recovered d4e5f6aReflog for a branch
git reflog show mainCherry-pick a lost commit
git cherry-pick d4e5f6aCommon mistakes
- Running git gc --prune=now before recovering.
- Assuming reflog exists on another machine.
- Panicking instead of checking reflog.
Key takeaways
- reflog = history of HEAD moves.
- Recover with reset or a new branch.
- Local only, time limited.
FAQ
How long does reflog last?
By default about 90 days for reachable and 30 days for unreachable entries.
Does it track uncommitted work?
No, only commits.