Git 2 reference · Undoing Changes
git reflog Command (Git)
Show where HEAD and branches have pointed recently, so you can recover commits after a reset or bad rebase.
Git 2
Syntax
git reflog [show REF]
Parameters
| Parameter | Description |
|---|---|
HEAD@{N} |
Where HEAD was N moves ago. |
Examples
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo a > a.txt; git add .; git commit -q -m 'Important work'
git reset -q --hard HEAD~1
git reflog --format='%gd %gs' | head -3
git reset -q --hard HEAD@{1}; git log --oneline
Output
HEAD@{0} reset: moving to HEAD~1
HEAD@{1} commit: Important work
HEAD@{2} commit (initial): Initial commit
a018c4c Important work
7f7f133 Initial commitRun this on your computer — see “Get Started” for setup.
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git switch -q -c x; git switch -q main
git reflog --format='%gs' | head -2
Output
checkout: moving from x to main checkout: moving from main to x
Run this on your computer — see “Get Started” for setup.
Related
git reset· Move the current branch to another commit, keeping changes staged (--soft), unstaged (default) or discarding them (--hard).git log· Show commit history: one line per commit, as a graph, filtered by author, date, path or message.- Recovering Lost Work with reflog · tutorial