How to Recover Deleted Commits or Branches with Git Reflog
Find and restore commits or branches that were accidentally lost after a hard reset, bad rebase, or branch deletion.
git reflogStep-by-Step Execution Guide
git reflogShows a chronological log of every HEAD change (commits, checkouts, resets) with identifiers like HEAD@{2}.
git reflog show --date=relativeHelps identify which point in time contained your lost work.
git checkout -b recovery-branch HEAD@{2}Creates a brand new branch pointing directly to the recovered commit state.
Critical Pitfalls & Precautions
- β’Reflog entries expire after 30 to 90 days depending on git gc settings.
Recover Lost Commits (Reflog) - Frequently Asked Questions
Common questions about safe rollback, remote history implications, and troubleshooting.
No. Git reflog only records commits. Unstaged, uncommitted files discarded with "git restore" cannot be recovered via reflog.
Related Git Command Guides
Browse All Git RecipesUndo your most recent Git commit while keeping all your edited files staged or unstaged in your working directory.
Discard all unstaged and uncommitted file modifications and restore your working tree to the latest commit.
Rename your current local branch and update the upstream remote tracking branch on GitHub or GitLab.
Delete a branch from remote origin (GitHub, GitLab, Bitbucket) after a pull request has been merged.
Amend the commit message of your latest commit before or after pushing.
Remove files from the Git staging area (index) without losing any of your local changes.