Skip to main content
>_ supraj.dev
TOPIC GIT
The Reflog git's undo button
IN 10 SECONDS

Git maintains a local log (reflog) recording every time branch pointers move (checkouts, commits, rebases, resets). It allows you to recover deleted branches or lost commits.

GOTCHA The reflog is local to your machine. It is never pushed to remote servers, and entries are deleted after 90 days by default.
HOW THE REFLOG RECOVERS COMMITS
01 Mistake developer runs git reset --hard HEAD~1, deleting their work commit.
02 Query runs git reflog, listing previous pointer locations.
03 Identify SHA locates commit hash before reset: HEAD@{1} was 'feat: new app'.
04 Recovery runs git checkout or git reset to recover commit files instantly.
POKE IT YOURSELF
git reflog — show history of local branch pointer updates
git reset --hard HEAD@{1} — revert repo pointer back to a reflog state