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.
Inspect reference updates for a named branch.
git reflog show mainUseful when the recovery target involves a branch ref rather than the current HEAD movement.
See what would be pruned from reflog without changing anything.
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.
Move the current branch back to a previous recorded state.
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.
Inspect a recovered commit before deciding what to do with it.
git checkout <lost_commit_sha>Detached HEAD checkout is useful for verifying that a reflog-discovered commit is the one you want to recover.
Apply a recovered commit onto the current branch.
git cherry-pick <lost_commit_sha>Useful when you only need one or a few recovered commits rather than rewinding the whole branch.
List objects that are no longer reachable from refs.
git fsck --lost-foundHelpful when reflog is insufficient and you suspect commits still exist as dangling objects.
Restore deleted branches and previous branch tips.
Use ORIG_HEAD as a quick recovery anchor.
git branch recovered-orig ORIG_HEADORIG_HEAD often points to the pre-operation tip after merge, pull, reset, or rebase.
Find likely commit hashes for branch recovery.
git reflog --all | grep feature-branchSearch across all reflogs when recovering branch pointers that were deleted or force-updated.
Move a branch ref to a specific commit hash.
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.
Inspect a previous HEAD state without changing refs.
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.
Customize how long normal reflog entries are retained.
git config --global gc.reflogExpire 90.daysLonger reflog retention can improve recovery options in repositories with heavy history editing.
Control retention for entries that are no longer reachable.
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.
Check repository object counts and size details.
git count-objects -vHUseful during repository maintenance and when reasoning about how much potentially recoverable loose object data exists.