Git reflog: Recovering Lost Commits and Deleted Branches
Every ref movement is logged locally for ninety days. How to undo a reset, restore an amended commit, and what fsck can still find when the log is gone.

Quick Summary
The reflog is a local, append-only log of where each ref has pointed. Every commit, merge, rebase, reset, checkout, and amend writes an entry, so a branch you deleted or a commit you rewrote is almost always still reachable — for 90 days by default for reachable entries, 30 days for unreachable ones.
Two things make it indispensable. First, git reflog shows HEAD movement, which is what you need after "my branch is gone". Second, any reflog entry can be used as a revision: HEAD@{1}, main@{yesterday}, stash@{2}.
What the reflog is not: it is not shared. A fresh clone has one entry per branch pointing at the clone-time tips, and no history of what happened on the origin. Recovery of anything that was never on your machine comes from someone else's clone, not from your reflog.
Basic Syntax and Core Signatures
git reflog # HEAD movement, newest first
git reflog show main # one branch
git reflog show --all --date=iso
git reflog expire --dry-run --expire=now --all # what would be pruned
# Any reflog entry is a revision
git show HEAD@{1}
git diff main@{yesterday} main
git switch -c rescue HEAD@{3}
git reset --hard HEAD@{1} # undo the last reset
git branch recover main@{2}
# Config
git config --global gc.reflogExpire 90.days
git config --global gc.reflogExpireUnreachable 30.days
# Dangling and unreachable objects: the fallback when the reflog is gone
git fsck --lost-found # writes dangling commits to .git/lost-found/commit/
git fsck --unreachable --no-reflogs
git show <dangling-sha>A reflog entry looks like this, and the middle columns are the operation that created it:
3f2a1b9 HEAD@{0}: reset: moving to HEAD~1
9c1e2f4 HEAD@{1}: commit: feat: add retry budget
5d6e7f8 HEAD@{2}: rebase (finish): returning to refs/heads/mainKey Comparison Table
| Reference | Resolves to | Survives a clone | Changes when |
|---|---|---|---|
HEAD~2 | Second ancestor of HEAD | Yes | Commits change |
HEAD@{2} | Where HEAD was two moves ago | No, local only | Any ref movement |
main@{yesterday} | main at the end of that day | No | Daily granularity |
@{-1} | Previously checked-out branch | No | Switching |
refs/stash | Newest stash commit | No | Stash push |
| Dangling commit | Committed object with no ref | Objects may be copied by a clone only if reachable | Garbage collection |
| Situation | Recovery command |
|---|---|
| Branch deleted, was not merged | git branch <name> <sha from reflog> |
reset --hard discarded commits | git reset --hard HEAD@{1} |
| Amended commit replaced | git switch -c fix <old sha> from reflog |
| Rebase lost the original branch | git reflog, then git reset --hard HEAD@{n} |
| Dropped stash | git fsck --unreachable, then git stash apply <sha> |
| Commits from a deleted remote branch | A colleague's clone, or the hosting service's API |
Practical Edge Cases and Deep Dives
1. Recovering a deleted branch
git branch -D deletes the ref, not the commits. The reflog for HEAD shows the last commit that branch pointed at, provided you were on it at some point:
git reflog --date=iso | grep -i "feature/login"
# 9c1e2f4 HEAD@{4}: commit: feat: rate limit login
git branch feature/login 9c1e2f4If you never checked the branch out, its reflog still exists under git reflog show feature/login until the entry expires — but after deletion there is no name to query. git fsck --lost-found is then the only route, and it lists every dangling commit, which is a long list on a busy repository.
2. Undoing a reset the wrong way
A reset moves HEAD and writes a reflog entry for the reset itself, so HEAD@{1} is the state before it. Two consecutive resets mean HEAD@{2}. Reading the reflog before acting is the whole technique:
git reflog -8
# 3f2a1b9 HEAD@{0}: reset: moving to HEAD~1 <- the mistake
# 9c1e2f4 HEAD@{1}: commit: feat: add retry budget <- what you want back
git reset --hard HEAD@{1}git reset --hard HEAD@{1} after a rebase returns to the pre-rebase tip, including the original commit hashes.
Two details make the fix reliable. The reflog entry you want is the one whose operation starts with commit: or rebase (start):, not the one created by the reset itself. And HEAD@{1} is stable only until your next Git command — every operation appends an entry, so act before running anything else, or copy the hash out of git reflog and use the hash directly. Hashes do not shift; indices do.
3. Recovering an amended commit
git commit --amend creates a new commit and moves the branch; the old one is still in the reflog as the previous entry. Recovering it means branching from it and diffing against the amended version to see what was lost:
git reflog -3
git switch -c recovered 5d6e7f8
git diff recovered main4. Expiry, garbage collection, and what is actually permanent
Reachable reflog entries expire after gc.reflogExpire (90 days); entries pointing at commits no longer reachable expire after gc.reflogExpireUnreachable (30 days). After that, git gc can delete the objects. CI machines and fresh clones also effectively reset the clock, which is why a repository re-cloned weekly has short recovery windows.
git gc --prune=now --aggressive # destructive; never run to "clean up" before a recoveryPrevious-reference forms. Three different "previous" references with different meanings. HEAD@{1} is the previous position of HEAD in the reflog, regardless of operation. @{-1} is the previously checked-out branch, which is what git switch - uses. ORIG_HEAD is set by operations that rewrite history — merge, rebase, reset — and holds the pre-operation tip. Scripts that meant "undo the merge" should use ORIG_HEAD, which is less ambiguous than counting reflog entries.
5. The reflog on the server is not yours
A remote's reflog records pushes to that remote's refs, and you cannot read it without shell access to the server. That means a force-push that overwrote a colleague's commits is recoverable only if their clone still has them, or the hosting provider keeps the old ref (GitHub exposes it through the events API and the compare view for a limited time). The local reflog protects local work; protecting shared work is a matter of policy, not of Git. A team that force-pushes without a lease is one accidental overwrite away from a lost afternoon, and the reflog only helps the person who still has the entry.
None of this changes how a team should work. A force-push to a shared branch is still a rewrite of someone else's history, and the fact that it can be recovered from a laptop does not make it a low-cost action; the cost is a colleague's afternoon, and it lands on them rather than on you.
6. Reading a reflog as a history of intent
Beyond recovery, the reflog is the only record of operations that leave no trace in git log — resets, checkouts, rebases, amends. When a colleague reports "something happened to my branch last Tuesday", git reflog --date=iso is the first command to run, and git diff <sha>@{day before} <sha>@{day after} shows what changed. On a shared machine or a build agent, the reflog also explains the mysterious extra commits a deployment script left behind, because each push and reset appears with its timestamp.
git reflog --date=iso main | head -20
git log --oneline --since="2026-11-12 00:00" --until="2026-11-13 00:00" mainCommon Git Operation Mistakes
| Symptom | Cause | Fix |
|---|---|---|
| "fatal: ambiguous argument 'HEAD@{1}'" | No prior reflog entry, or the shell ate the braces | Quote the argument, check git reflog length |
| Recovered commit is empty or unrelated | Wrong index into a long reflog | Read the entries with --date=iso, match the message |
fsck lists hundreds of commits | Busy repository, many dangling objects | Filter by date or author, inspect with git show |
| Reflog gone after re-clone | Reflog is local | Recover from the origin or a colleague's clone |
| Force-push destroyed remote commits | Overwrote a shared ref | Partner's clone, provider event log |
git gc deleted the objects before recovery | Expiry passed, or --prune=now used | Nothing left; restore from a backup |
| Branch restored at the wrong tip | Picked a reset entry instead of the commit entry | Read the operation column |
@{yesterday} resolves oddly | Local timezone and day boundary | Use --date=iso with HEAD@{<sha>} or a timestamp |
Try matching browser tools
All toolsSmall utilities that fit Git work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Git guides
All Git guidesGit config: Aliases, rerere, and Credential Helpers
Five config scopes decide one value at a time. Aliases are user-level shorthand, rerere records conflict resolutions, and credential helpers choose where your secret lives.
Git Hooks: pre-commit, commit-msg, and Husky Automation
Hooks live in .git/hooks, which a clone never receives, so core.hooksPath and Husky are how they travel. Exit codes abort the operation, and every hook is bypassable.
Git bisect: Binary Search, Automated Scripts, and Bug Hunting
Mark one bad and one good commit and Git halves the range each step. bisect run automates it through exit codes, and monotonicity is the assumption that must hold.
Git ignore: Patterns, Negation, and Untracking Cached Files
Patterns are relative and last match wins, but a negation cannot revive a file inside an excluded directory. Ignore rules never touch tracked files: rm --cached first.
More in Git
All Git guidesThe guides filed next to this one in Git, in library order.