Recover Lost Work With git reflog

Find and restore commits after an accidental reset, rebase or branch delete.

macOSbackupgitcliLow risk
Run git reflog to list recent HEAD positions, then reset or cherry-pick the commit you need.

01Command

Command
$ git reflog

02What it does

The reflog is a local journal of every ref movement, including commits no longer reachable from a branch. It is the safety net that makes command-line history editing safe, and it has no repository UI equivalent for recovering detached or discarded commits.

03Risk

RiskLow risk
RequirementsGit 2.20+ (install with Homebrew or Xcode Command Line Tools)
CompatibilitymacOS with Git installed (Homebrew or Xcode Command Line Tools)
!Warning: Reflog entries expire after the default retention period, so recover quickly and copy the SHA somewhere safe.

04Undo

Undo
$ git reset --hard HEAD@{1}

05Sources

  • git-reflog documentation
    Git · vendor-doc · 2026-09-20
    Evidence: Documents the reflog, which records where HEAD and branches have pointed.

Last verified: 2026-10-13 · Category: Developer

06Related solutions