Day 12intermediateFeb 12, 2026

Recover Lost Commits with Git Reflog

Git reflog is your undo button — it can recover commits you thought were gone forever.

gitrecoverydebugging
Share:

What

Git reflog records every change to HEAD, even ones that no longer appear in git log. Every checkout, commit, rebase, reset, and merge is tracked. It's your safety net for recovering 'lost' commits after a bad rebase or reset.

Why It Matters

Mistakes happen — a bad rebase, an accidental reset --hard, or a force push can make commits seem to vanish. Without reflog, you'd have no way to find those orphaned commits. Reflog keeps a local history of every HEAD movement for 90 days for reachable entries (30 days for unreachable entries by default).

Example

# View the reflog to find lost commits
git reflog

# Output looks like:
# a1b2c3d HEAD@{0}: reset: moving to HEAD~3
# f4e5d6c HEAD@{1}: commit: add user authentication
# e1f2a3b HEAD@{2}: commit: fix login bug

# Recover by checking out the lost commit
git checkout f4e5d6c

# Or reset your branch to that commit
git reset --hard f4e5d6c

# Or create a new branch from the lost commit
git branch recover-branch f4e5d6c
bash

Common Mistake

Panicking and thinking commits are gone forever after a reset --hard. Many developers don't know about reflog and assume the commits are unrecoverable, sometimes even re-cloning the repo and redoing work.

Quick Fix

Run git reflog immediately after the mistake. Find the SHA of the commit you want to recover, then use git reset --hard <sha> to restore your branch or git cherry-pick <sha> to bring back specific commits.

Key Takeaways

  • 1git reflog tracks every HEAD movement locally
  • 2Commits survive reset, rebase, and amend for ~90 days
  • 3Use git reflog to find the SHA of lost commits
  • 4Recover with git reset --hard <sha> or git cherry-pick <sha>
  • 5Reflog is local only — it won't help on a different machine

Was this tip helpful?

Help us improve the DevOpsPath daily collection

Share: