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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git reflog [show REF]

Parameters

ParameterDescription
HEAD@{N} Where HEAD was N moves ago.

Examples

Recover a commit after reset --hard
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 commit

Run this on your computer — see “Get Started” for setup.

Branch switches are recorded too
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.

Was this page helpful?