patternMajorpending
Git reflog — recovering lost commits and branches
Viewed 0 times
refloglost commitrecoveryreset --harddeleted branchfsckunreachable
terminal
Problem
Accidentally deleted a branch, ran git reset --hard, or lost commits after a bad rebase. The commits seem gone and git log doesn't show them.
Solution
Use git reflog — it records every HEAD movement for 90 days. (1) Find the lost commit: git reflog — look for the commit hash before the destructive operation. (2) Recover: git checkout -b recovery-branch <commit-hash>. (3) After bad reset: git reset --hard <reflog-hash> to go back. (4) After deleted branch: git branch recovered-branch <commit-hash>. (5) After bad rebase: find the pre-rebase commit in reflog and reset to it. (6) Reflog is local only — it doesn't help with changes that were never committed. (7) For recovering staged but uncommitted changes: git fsck --lost-found.
Why
Git rarely deletes data immediately. Unreachable commits stay in the object database until garbage collection (gc.pruneExpire, default 2 weeks). Reflog maintains a history of all ref updates.
Revisions (0)
No revisions yet.