Recovering from a Botched Rebase

A real rebase, conflict and all, completed — then undone entirely, in one command.

feature/pantry-audit and master both genuinely edited the same real shared file. Rebasing the feature branch onto master hits a real conflict — resolved by hand, the rebase completes successfully. Only afterward does it become clear the resolution was not actually right.\n\nFixing a completed rebase commit by commit would mean another real interactive rebase, more conflict resolution, more risk. git sets ORIG_HEAD automatically before every real, potentially destructive operation — rebase included — as a genuine one-step undo. reset --hard ORIG_HEAD throws away the entire rebase in a single command, back to the exact real state from right before it started.

A Real Conflict, Resolved

git rebase master
# CONFLICT (content): Merge conflict in kitchen-tips.md

Both branches genuinely edited the same real file. Resolving it by hand and running git rebase --continue completes the rebase — successfully, by git's own definition.

Realizing It Was Wrong

Sometimes the "successful" resolution is not actually the one that was wanted — a real line got dropped, merged oddly, or simply does not read right on a second look.

One Command, Fully Undone

git reset --hard ORIG_HEAD

git automatically records ORIG_HEAD before rebase (and before merge, and before reset itself) as a real, one-step undo. This throws away the entire rebase — every replayed commit, every conflict resolution — landing back exactly where the branch was before git rebase ran.

ORIG_HEAD

A real ref git sets automatically before potentially destructive operations — rebase, merge, reset itself — pointing at wherever the branch was right before. Confirmed directly in this lab: it held the exact pre-rebase tip even after the rebase completed successfully.

reset --hard ORIG_HEAD

Undoes an entire real, completed operation in one command — every replayed commit, every conflict resolution — rather than fixing it piece by piece. Confirmed directly in this lab: the branch returned to its exact pre-rebase parent and content.

⚡ Rebase Into a Real Conflict

Two branches, the same real shared file. This genuinely conflicts.

cd ~/team-recipes && git switch feature/pantry-audit
cd ~/team-recipes && git rebase master

student@lab:~$ cd ~/team-recipes && git switch feature/pantry-audit Switched to branch 'feature/pantry-audit' student@lab:~$ cd ~/team-recipes && git rebase master Rebasing (1/1) Auto-merging kitchen-tips.md CONFLICT (content): Merge conflict in kitchen-tips.md error: could not apply a1615d5... Add pantry audit tip hint: Resolve all conflicts manually, mark them as resolved with hint: "git add/rm <conflicted_files>", then run "git rebase --continue". hint: You can instead skip this commit: run "git rebase --skip". hint: To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply a1615d5... Add pantry audit tip

🩹 Resolve It and Finish (Regrettably)

Resolved by hand, the rebase completes successfully.

cd ~/team-recipes && printf 'Kitchen Tips\n\nPreheat the oven before starting any bake recipe.\n\nAlways preheat for at least 12 minutes before baking (see PR #142 for the oven latency testing behind this number).\n\nLet meat rest 5 minutes after cooking before slicing.\n\nAudit the freezer quarterly for freezer burn.\n\nAudit the pantry monthly and discard anything past 6 months.\n' > kitchen-tips.md
cd ~/team-recipes && git add kitchen-tips.md
cd ~/team-recipes && git rebase --continue
cd ~/team-recipes && git log --oneline -3

student@lab:~$ cd ~/team-recipes && printf 'Kitchen Tips\n\nPreheat the oven before starting any bake recipe.\n\nAlways preheat for at least 12 minutes before baking (see PR #142 for the oven latency testing behind this number).\n\nLet meat rest 5 minutes after cooking before slicing.\n\nAudit the freezer quarterly for freezer burn.\n\nAudit the pantry monthly and discard anything past 6 months.\n' > kitchen-tips.md student@lab:~$ cd ~/team-recipes && git add kitchen-tips.md student@lab:~$ cd ~/team-recipes && git rebase --continue hint: Waiting for your editor to close the file... [detached HEAD cb692bc] Add pantry audit tip 1 file changed, 2 insertions(+) Successfully rebased and updated refs/heads/feature/pantry-audit. student@lab:~$ cd ~/team-recipes && git log --oneline -3 cb692bc (HEAD -> feature/pantry-audit) Add pantry audit tip f3bbb65 (master) Add freezer audit tip aa3c1bf Add air fryer fries recipe

⏮️ Undo the Entire Thing

One real command, back to exactly before the rebase started.

cd ~/team-recipes && git reset --hard ORIG_HEAD
cd ~/team-recipes && git log --oneline -3

student@lab:~$ cd ~/team-recipes && git reset --hard ORIG_HEAD HEAD is now at a1615d5 Add pantry audit tip student@lab:~$ cd ~/team-recipes && git log --oneline -3 a1615d5 (HEAD -> feature/pantry-audit) Add pantry audit tip aa3c1bf Add air fryer fries recipe a9cb3cd Add instant pot risotto recipe

Lab 3.4.5 complete — Block 3.4 complete. A real rebase, conflict and all, undone entirely in one command:\n\n\n git rebase master : ✅ real conflict hit\n Resolved + continued : ✅ rebase completed\n reset --hard ORIG_HEAD: ✅ entirely undone\n

Enable JavaScript to run the live terminal and track your progress.