Git Reflog
Last updated
git reflog records every place HEAD has pointed - every commit, checkout, reset, and rebase. Because Git keeps those commits around for a while even after they leave your branches, the reflog is your safety net: it lets you find and recover work that a reset --hard, a bad rebase, or a deleted branch seemed to destroy.
Try these in the terminal playground - a real shell in your browser, nothing to install.
Syntax
| Command | What it does |
|---|---|
git reflog | Show recent positions of HEAD, with hashes |
git reflog show <branch> | Show the reflog for a branch |
git reset --hard HEAD@{1} | Jump HEAD back to a previous position |
git branch recovered <hash> | Recreate a branch at a lost commit |
Recovering after a mistake
Undo a bad reset by finding the pre-reset commit.
| Step | Command | Result |
|---|---|---|
| 1 | git reflog | Find the commit before the reset |
| 2 | git reset --hard HEAD@{1} | Restore your branch to it |
Git reflog FAQ
What is git reflog?
It's a log of everywhere
HEAD (and each branch tip) has pointed in your local repository - after commits, checkouts, resets, merges, and rebases. Unlike git log, which follows commit ancestry, the reflog is a chronological record of your actions, which is what makes it useful for recovery.How do I recover a commit after git reset --hard?
Run
git reflog to find the entry for the commit you were on before the reset (something like HEAD@{1}), then git reset --hard <that-hash> (or HEAD@{1}) to return to it. The commit wasn't truly deleted - it just had no branch pointing at it, and the reflog still knows its hash.How do I restore a deleted branch?
Find the branch's last commit in
git reflog, then recreate the branch there: git branch <name> <hash>. As long as the deletion was recent (within Git's reflog expiry, typically weeks), the commits are still reachable this way.Does git reflog work across clones?
No - the reflog is local to your repository and isn't pushed or cloned. It only records actions on your machine. That's why it can rescue local mistakes but can't recover something that only ever existed on a different clone.
Can I practice this online?
Yes. Open the terminal playground to run
git reflog in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers undoing changes and recovery step by step.