Git Disaster Recovery Without Panic
Thirty-three realistic Git recovery problems. Practice reading reflogs and saving lost commits, including work left on detached HEAD. Learn which undo command fits the situation and how to repair shared history without erasing a teammate's work.
Questions
- Not answered. You found a possible lost commit at
7ac91e2. What should you do first? - Not answered. What does a Git reflog primarily record?
- Not answered. Why can
HEAD@{2}name a different commit fromHEAD~2? - Not answered. After your local hard reset, a teammate makes a fresh clone. Can they inspect your old
HEAD@{1}? - Not answered. How should you recover this clean, private branch after an accidental reset?
- Not answered. A deleted branch's commit still appears in a reflog. How do you restore the branch?
- Not answered. You made a useful commit while
HEADwas detached, andHEADstill points to it. How do you keep it? - Not answered. You already switched away from commits made on a detached
HEAD. How do you recover them? - Not answered. Which statements about commit-level
git resetmodes are true? - Not answered. How do you unstage
config.tswhile keeping its working-tree edits? - Not answered. How do you restore only
src/parser.tsfrom commita41d2c0into the working tree? - Not answered. A bad commit reached a shared, protected branch. How should you normally undo it?
- Not answered. How do
git revertand a commit-levelgit resetdiffer? - Not answered. Why must you normally choose a mainline parent when reverting a merge?
- Not answered. Which commands match the stated goal?
- Not answered. What usually happens to commits that rebase replays onto a new base?
- Not answered. A rebase stopped at a conflict. Which statements are true?
- Not answered. How does
git rebase --quitdiffer fromgit rebase --abort? - Not answered. Why should
ORIG_HEADnot be your only bookmark during a complicated recovery? - Not answered. An interactive rebase produced the wrong result. Where should you look for the old branch tip?
- Not answered. After upstream was rewritten, what does
git rebase --onto origin/main origin/main@{1} topictry to do? - Not answered. After a coordinated rewrite, which push rejects an unexpected update to remote
main? - Not answered. Why is
--force-with-leaseweaker without an expected object ID when tools fetch in the background? - Not answered. A force-push removed commits from the server branch, but a coworker still has them. What should the team do?
- Not answered. After
git fetchsees a force-update toorigin/main, where might the old tip still appear? - Not answered. The reflog no longer names a lost commit, but the object may still exist. Which command can find dangling objects?
- Not answered. By default, when do unreachable reflog entries become eligible for expiration?
- Not answered. Which facts explain why a reflog is not a backup system?
- Not answered. Can a reflog reliably recover unstaged edits erased by
git reset --hard? - Not answered. You recovered one useful commit and want to add its change to the current branch. What should you use?
- Not answered. Three unpublished commits landed on
main. How do you move them to a topic branch? - Not answered. A merge stopped at conflicts, and you want to abandon it. Which command should you run?
- Not answered. What is the safest order of work after a possible history-loss incident?