git reflog
Show the reference log — your safety net for lost commits
Practical Example
git reflog
# abc1234 HEAD@{0}: commit: Fix login bug
# def5678 HEAD@{1}: reset: moving to HEAD~1
# Recover: git branch recovered-branch abc1234Command Overview & How It Works
Records every movement of HEAD — every checkout, commit, reset, rebase, and merge. When you accidentally lose commits (from a hard reset, rebase gone wrong, or deleted branch), the reflog is your recovery tool. Each entry shows the operation, the previous position, and how HEAD moved. Use git reflog to find the commit hash of a lost state, then git checkout <hash> or git branch <name> <hash> to recover it. The reflog is local — it is not shared with remotes and is not backed up. Entries expire after 90 days (for reachable commits) or 30 days (for unreachable). Use git reflog show <branch-name> to see the reflog for a specific branch. The reflog is why Git is hard to permanently lose data from.
Practical Tips
- •Check git reflog first whenever a reset or rebase 'loses' work — your commits are usually still recoverable.
- •The reflog is local to your machine and not shared with remotes, so push important branches early.
- •Recreate a deleted branch with git branch <name> <hash> using the hash you find in the reflog.