git reflog
Show where HEAD and branches have been
The 'git reflog' command lists every position HEAD has had: each commit, switch, reset, merge and rebase, newest first. It is local to your repository and is the safety net for lost work — commits removed from a branch by a reset or a rebase are still listed and can be recovered with HEAD@{n}. Entries expire after 90 days by default.
Synopsis
git reflog [show] [<log-options>] [<ref>]Options
Choosing the Right Option
log vs reflog
Two histories
| Command | Lists | Shared? |
|---|---|---|
git log | Commits reachable from a branch | Yes, with the commits |
git reflog | Every move of HEAD, even to commits no branch has | No, local only |
Examples
List moves of HEAD
git reflogNewest first, with HEAD@{n} names.
Undo a reset
git reset --hard HEAD@{1}Go back to where HEAD was one move ago.
Reflog of a branch
git reflog show mainMoves of main only.
Workflow Examples
git reflogFind the entry before the reset
git reset --hard HEAD@{1}Move back to it
git reflogFind the last commit of that branch
git switch -c feature/login a1b2c3dRecreate the branch there
Troubleshooting
The commit is not in the reflog
Cause: It was never checked out here, or the entry expired
Try git fsck --lost-found for dangling commits
HEAD@{1} points somewhere unexpected
Cause: Every switch also counts as a move
Read the reflog and pick the exact entry
Tips & Pitfalls
Best Practices
- ✓Check git reflog before panicking about lost commits.
- ✓Recover with a new branch first (git switch -c rescue <hash>) to inspect safely.
Common Mistakes
- ✗Thinking a hard reset deleted commits for good — the reflog still has them.
- ✗Waiting too long: unreachable commits disappear once reflog entries expire and git gc runs.
- ✗Expecting the reflog on another machine — it is never pushed or cloned.
FAQ
90 days for reachable entries, 30 days for unreachable ones, by default.
No, it only lists. git reflog expire and delete are the ones that remove entries.