git reflogReflog is local-only and records where refs pointed over time, which makes it invaluable for recovery.
Recover commits, branches, and work after resets, rebases, deletes, and mistaken force updates.
Inspect reference movements and recent branch history changes.
git reflogReflog is local-only and records where refs pointed over time, which makes it invaluable for recovery.
git log -g --oneline --decorate`git log -g` formats reflog traversal as commit log output, which many users find easier to scan.
git reflog show mainUseful when the recovery target involves a branch ref rather than the current HEAD movement.
git reflog expire --expire=30.days --all --dry-runMostly administrative, but useful when troubleshooting object reachability and retention.
Find and restore commits after destructive operations.
git reset --hard HEAD@{3}Strong recovery option after bad rebase, reset, or merge. Verify the target first because `--hard` discards working tree changes.
Create a new branch from a reflog entry without moving current branch yet.
git branch recovered-work HEAD@{3}Safer than immediately hard-resetting because it preserves your current branch while giving you a recovery pointer.
git checkout <lost_commit_sha>Detached HEAD checkout is useful for verifying that a reflog-discovered commit is the one you want to recover.
git cherry-pick <lost_commit_sha>Useful when you only need one or a few recovered commits rather than rewinding the whole branch.
git fsck --lost-foundHelpful when reflog is insufficient and you suspect commits still exist as dangling objects.
Restore deleted branches and previous branch tips.
git branch recovered-orig ORIG_HEADORIG_HEAD often points to the pre-operation tip after merge, pull, reset, or rebase.
git reflog --all | grep feature-branchSearch across all reflogs when recovering branch pointers that were deleted or force-updated.
git update-ref refs/heads/feature <commit_sha>Low-level but useful when you know the exact target and want to repair a ref directly.
git switch --detach HEAD@{3}A safe way to inspect old states before deciding to branch or reset.
Retention, garbage collection, and recovery-friendly practices.
git config --global gc.reflogExpire 90.daysLonger reflog retention can improve recovery options in repositories with heavy history editing.
git config --global gc.reflogExpireUnreachable 30.daysImportant if you often rewrite history and want a wider window for recovery.
git gc --prune=nowUse carefully. Immediate pruning can remove recovery options for unreachable objects sooner than expected.
git count-objects -vHUseful during repository maintenance and when reasoning about how much potentially recoverable loose object data exists.