Skip to main content
Handbook/Debug/Page 61 · Rollback

Reverting Safely

Share

Share this page

Pass it to someone who needs it.

Star on GitHub

Key takeaway: Revert without losing work

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:

git revert a1b2c3d

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:

git reset --hard 9f8e7d6 # deletes ALL work after 9f8e7d6

Revert is surgical and safe to run. A hard reset destroys history, so it is the move you almost never want here.

Revert cancels just the bad commit; a hard reset destroys every change after it.

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.

Where the mess lives decides the exit: drop a bad branch, or revert the last commit on main.

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 fixFix forward
has you stuck, or you cannot explain whyRoll back
left you debugging in a panicRoll 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:

Ready prompt
Act as a senior engineer doing damage control. A recent change made things worse and I need it undone safely. Read my repro steps and the diagnosis I already wrote before you touch git. Rules: - Find the exact commit that caused the problem. - Undo ONLY that commit with a revert, a new commit that cancels it out. Never hard-reset or delete work I did after the bad change. - If several recent changes are tangled, get me back to the last commit that ran, and tell me which one that is. - Run my quality gate and confirm the app works again before we move on, then advise: fix forward now, or roll back and retry later. If you need the full reasoning behind this step, read https://zalt.me/guides/vibe-coding/debug/rollback The bad change I need to undo:

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.

Mahmoud Zalt

Mahmoud Zalt

Software engineer, 16+ yrs · built Sistava.com in 3 months, idea to production, using these methods

Resources
Star on GitHubContribute
Donate

Support my work

A small tip keeps the free work coming.

© 2026 Mahmoud Zalt. Free to read, not to republish.
Copyright & license