The attempt went bad. Now what?
You asked the agent to add a CSV export. Forty minutes later the app won't start. The agent has edited six files, made two commits of its own and created a new helper file. Now it says:
◂ Agent: Apologies — one more fix should do it.
Your checkpoint commit from before the task is still there. Do you let it try once more? Or do you go back, and how far?
Undo the bad work, not just the symptom
The bad idea now lives in two places: the files, and the agent's conversation. More fixes build on both. Thanks to the checkpoint, going back only costs the minutes already spent.
Two questions pick the undo. Is the bad work **committed** yet? Is **good work mixed in with it or sitting on top of it**? Undo exactly the bad part. Then restart using what the failure taught you.
Pick the recovery that fits
First look: `git status` shows uncommitted edits. `git log --oneline` shows which commits came after the checkpoint.
- **Bad edits uncommitted, the rest worth keeping:** `git restore <file>` on just the bad files.
- **Whole attempt bad, even with commits made during it:** `git reset --hard <checkpoint>`. Everything after it is lost for good.
- **One bad commit with good commits after it:** `git revert <commit>`.
Restore and reset never remove new untracked files. `git clean` does that (next card).
Back to the checkpoint, fully
The agent's two commits sit on top of checkpoint `e51f0c2`. `git reset --hard` drops them and all uncommitted edits. The new helper file is untracked, so reset leaves it behind. `git clean -n` previews what would be deleted, and `-f` deletes it. Check the preview first, because `git clean -f` deletes your own untracked files too. When `git status --short` prints nothing, you are exactly at the checkpoint.
$ git log --oneline -3
9c1e7aa fix export again
4b2d810 add CSV export
e51f0c2 before CSV export
$ git reset --hard e51f0c2
HEAD is now at e51f0c2 before CSV export
$ git status --short
?? src/export_utils.py
$ git clean -n
Would remove src/export_utils.py
$ git clean -f
Removing src/export_utils.py
$ git status --short
Restart with what you learned
Say the stack trace showed that the agent's change to `load_rows()` broke startup. Typing "still broken, try again" just repeats the request that failed. Do this instead:
▸ You: I reset all files to commit `e51f0c2`, so your export edits are gone. Add CSV export in `src/report.py` only. Last time, changing `load_rows()` broke startup, so leave it as is. Afterwards run `pytest` and `python app.py`.
Mention the reset, because the agent's conversation still describes edits that no longer exist. A fresh session also clears the bad idea. There, skip the reset line but keep the lesson.
Remember
Find where the bad work lives and undo exactly that. Use `git restore` for bad uncommitted files, `git reset --hard <checkpoint>` for a whole failed attempt, and `git revert` for one bad commit under good ones. Then restart with a sharper prompt that names what went wrong. Don't pile on another fix.
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.