- Readers handling reset, rebase, and branch-loss incidents
Command Reference
git reflog
Read reference movement history, which makes reflog one of the most important commands for recovery after reset, rebase, and branch mistakes.
- Knowing that reflog tracks ref movement
- A habit of inspecting positions before moving branches
- Treating reflog as permanent storage
- Jumping straight to overwrite the branch instead of making a rescue branch
git reflog records where refs such as HEAD have pointed over time. That makes it central to recovery workflows.
Why it matters
After operations like:
reset --hardrebasepull- branch deletion or history rewrite
the old commits may still exist, but the visible branch name may no longer point at them. Reflog helps you find those older positions.
Common examples
git reflog
git reflog show HEAD
git reset --hard HEAD@{1}
git checkout -b rescue HEAD@{2}
Best workflow
- inspect reflog
- locate the pre-mistake position
- either create a rescue branch or move the ref back
Key distinction
git logshows commit historygit reflogshows reference movement history
That difference is why reflog is so useful when normal history still exists but your pointer is no longer where you expected.
What problem this command solves in a workflow
git reflog is a read-only diagnostic tool that records the history of where references (especially HEAD and branch refs) have pointed. It does not modify commits, move refs, or reshape history — it simply reads and displays the ref movement log. Every checkout, reset, rebase, merge, and pull leaves a trail entry that reflog can surface, making it the primary recovery tool when you've lost track of a commit.
Typical use cases
- Recovering from an accidental
reset --hard— reflog shows you exactly where HEAD pointed before the reset. - Finding lost commits after a rebase or branch deletion — the old commits still exist in the object store; reflog reveals their hashes.
- Understanding what operations have been performed on a branch — reflog provides a chronological audit trail of ref changes.
- Creating a rescue branch at a specific historical position before attempting further corrective action.
Diagram view
Special cases and boundaries
- Reflog entries expire over time (default: 90 days for reachable entries, 30 days for unreachable). Do not treat reflog as a permanent archive — act quickly if you need recovery.
- Reflog is local to each repository. It is not shared via push/fetch, so you cannot recover ref movements that happened on another machine.
git reflog show <ref>shows the reflog for a specific ref (e.g.,refs/heads/main). Without arguments, it defaults to HEAD.- Reflog entries use syntax like
HEAD@{1}(one step ago) orHEAD@{2023-01-15}(position on a specific date). - Reflog only tracks ref movements, not arbitrary object creation. If a commit was never pointed to by a ref, it will not appear in reflog.
Try it yourself
The point of this drill is to experience that the pointer moved, but the old commit may still be recoverable.
git switch -c lab/reflog-demo # make two commits # then run git reset --hard HEAD~1Try it
- Run `git reflog` and find the HEAD position from before the reset.
- Create a rescue branch with `git checkout -b rescue/reflog HEAD@{1}`.
- Use `git log --oneline --graph --decorate --all` to compare the visible refs.
- You will see the old HEAD position recorded in reflog.
- The older commit usually still exists even though the current branch no longer points to it.
- Creating a rescue branch first is often safer than immediately hard-resetting again.
- Do not stack more resets or rebases before you identify the old position.
- Do not treat reflog like a permanent archive; act sooner rather than later.
- If the recovery move affects shared refs, evaluate the impact before changing them.