`git reflog` Is How You Recover From Bad Resets, Bad Rebases, and Other Bad Decisions Without Panic
A practical git reflog guide for developers who need to recover lost commits, undo dangerous history moves, and understand where HEAD used to point before the mess started.
Why this command matters emotionally as much as technically: when Git history goes wrong, people often assume their work is gone forever.
git reflogis the command that turns that panic back into a solvable problem.
What git reflog actually records
The Git documentation says reflogs record when the tips of branches and other references were updated in the local repository. That is the key idea. Reflog is not your commit history in the normal storytelling sense. It is a local record of where references like HEAD used to point.
That makes it incredibly useful after commands such as:
git reset --hardgit rebase- branch checkouts
- accidental branch moves
If your current history looks wrong, reflog often tells you where “right” used to be.
The first command to run
git reflogThis shows recent reference movements, often with entries like:
- checkout
- commit
- reset
- rebase
The exact wording matters less than the pattern: you are looking for the point before the destructive or confusing action happened.
Why this is different from git log
git log shows commits reachable from your current history shape. If you moved HEAD away from a commit, that commit may no longer be easy to find in normal log views.
Reflog helps precisely because it remembers the movements themselves. It can point you back to:
HEAD@{1}
HEAD@{2}
HEAD@{yesterday}That is why it feels like a rescue tool. It reveals where your repo state used to live before you rewrote it.
A practical recovery example
Suppose you ran a hard reset and immediately regretted it. A common recovery flow is:
git reflog
git reset --hard HEAD@{1}or reset to the specific commit hash you found in the reflog.
The important part is not memorizing one magic number. It is understanding that the reflog is giving you candidate prior states to return to.
Why this is especially useful after rebases
Rebases can leave people confused because the branch history is intentionally rewritten. If the result is not what you expected, reflog is often the shortest path back to the pre-rebase state.
That matters because the difference between “history is complex” and “my work is lost” is often just one recovery command and one calm inspection step.
Good habits during recovery
- inspect reflog before doing more destructive commands
- create a safety branch if you found the commit you care about
- only reset hard once you know exactly where you are going
This matters because a panicked recovery can create a second problem on top of the first one.
Why local matters here
Reflog is local state. That is both the strength and the limitation. It is great because it reflects what happened in your local repository. But it also means you should not assume another machine or teammate has the same reflog history.
That is why it is best used as an immediate local recovery tool, not as a universal record of all branch events everywhere.
Final recommendation
If you ever feel like Git “lost” your work after a reset, rebase, or branch move, run git reflog before assuming the situation is hopeless. Reflog often turns history disasters into recoverable navigation mistakes, which is a much better problem to have.