You changed something and the app got worse, not better. You have poked at it for twenty minutes and it is still broken. You have also done real work since that change, work you do not want to throw away. This chapter gets you out clean: undo the one bad change, keep everything else, and land back on a version that runs.
7.6.1Undo without losing unrelated work
Undoing a bad change does not mean throwing away the good work you did after it. Your history is a line of saved snapshots, and you can lift out exactly one of them while the rest stay put.
The trap is treating undo as all-or-nothing: deleting the last hour to kill one five-minute mistake. You never have to pay that price. Point your agent at the single change that broke things and leave everything else standing.
7.6.2Revert the one change
A revert is a new commit that cancels out one specific past commit and nothing else. The work you did after the bad change stays exactly where it is, because you are adding to history, not erasing it.
Your agent runs it against the commit that caused the trouble:
Contrast that with the bulldozer. A hard reset back to the last good commit throws away every change since, including the unrelated work you want to keep:
Revert is surgical and safe to run. A hard reset destroys history, so it is the move you almost never want here.
7.6.3Get back to a working state
Sometimes you do not need surgery, you need to stop the bleeding. If the last few changes are tangled and you cannot say which one broke things, get back onto the last version you know ran, then move forward from there.
If the work was on its own branch, the cleanest path is to throw that branch away and return to main, which never felt the damage. If the mess is already on main, revert the last commit to land back on solid ground without erasing anything.
Either way the goal is the same: a version that runs right now, so you can think clearly instead of debugging in a panic.
7.6.4Roll back vs fix forward
Every broken change forces one call: roll back or fix forward. Fix forward means leaving the change in and patching the problem on top. Roll back means undoing it now and retrying later with a clear head.
The rule is about time and understanding, not pride.
| The change... | Do this |
|---|---|
| broke in a way you understand, one-line fix | Fix forward |
| has you stuck, or you cannot explain why | Roll back |
| left you debugging in a panic | Roll back, then diagnose |
7.6.5Hand the undo to your agent
When a change goes bad, hand the cleanup to your agent with clear rules:
Do this now: the next time a change makes things worse, paste the prompt above with that change, and let your agent revert just that one commit instead of throwing away your afternoon.