GIT / A CONCEPT NOTE

The Reflog

git's undo button

~65 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

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.

02 / FOLLOW THE MECHANISM

How the reflog recovers commits

  1. Mistake

    developer runs git reset --hard HEAD~1, deleting their work commit.

  2. Query

    runs git reflog, listing previous pointer locations.

  3. Identify SHA

    locates commit hash before reset: HEAD@{1} was 'feat: new app'.

  4. Recovery

    runs git checkout or git reset to recover commit files instantly.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

show history of local branch pointer updates

git reflog

EXAMPLE 02 · REFERENCE

revert repo pointer back to a reflog state

git reset --hard HEAD@{1}

Explore command anatomy in the CLI lab