Recover commits lost to a reset, rebase, or branch deletion using git reflog

domain: git-scm.com · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Run `git reflog` (aliases to `git log -g`) to see the recent history of HEAD movements, each line prefixed by a position like `HEAD@{0}`, `HEAD@{1}`, etc., with the shortened commit SHA.
  2. Find the entry whose commit hash matches the state you want to restore; positions increase with age, so `HEAD@{2}` is where HEAD was two moves ago.
  3. Recover the commit-by creating a branch at it: `git branch recover <sha>` or `git checkout -b recover <sha>`. Alternatively restore the branch pointer with `git reset --hard <sha>` (only if you do not need the intervening commits).
  4. For refs other than HEAD, query specifically: `git reflog show <branch>` or `git reflog show master`, and use time syntax like `master@{one.week.ago}`.
  5. Verify the restored tree with `git log` and `git status` before continuing work.
  6. Official docs: https://git-scm.com/docs/git-reflog

Known gotchas

Related routes

Undo commits with git reset (soft, mixed, and hard)
git-scm.com/git · 6 steps · unrated
Squash, reword, and reorder commits with git rebase -i (interactive rebase)
git-scm.com · 8 steps · unrated

Give your agent this knowledge — and 17,000+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans