git reflog

Record all changes to HEAD and branch references, useful for recovering lost commits

Syntax

git reflog [show] [<options>] [<ref>]

Parameters

ParametersDescriptionExamplesLevel
show () Common
--all Common
-n <number> Common
expire --expire=<time> Common
--date=relative Common

Examples

HEAD

git reflog
abc1234 HEAD@{0}: commit: feat: def5678 HEAD@{1}: checkout: moving from main to feature 789abcd HEAD@{2}: reset: moving to HEAD~1

main

git reflog show main

3

git reset --hard HEAD@{3}

reflog

git checkout -b recover-branch abc1234

( 2 hours ago)

git reflog --date=relative

Tips

Related Commands