Topic 5 of 5 · 4 min read
Reviewing and reverting edits in the editor
Goal: Review an IDE agent's change set file by file and restore the code to a known good state when a change is wrong.
Review an agent's work in the editor the same way you would review a teammate's pull request: file by file, with a safe way back. The editor gives you three tools for it: per-file keep and undo, chat checkpoints and the source control view.
Check yourself · 1 of 3
What is the safest known good state to return to after an agent run goes wrong?
Why it matters
An agent change set is a draft until you keep it. The editor usually shows the edits as pending changes with Keep and Undo controls, per file or per hunk. If you hit "Keep all" without reading, the draft becomes your code. The tools to go back exist, but each one has limits, and it is much cheaper to know them before something breaks.
The three tools
- Keep and undo per file or hunk. Walk through the changed files one at a time. Keep the hunks that are right; undo the ones that are not. Undo only restores what the agent changed.
- Chat checkpoints. Some editors save a snapshot at each chat turn, such as Copilot's "Restore Checkpoint". Restoring rewinds the files the agent edited to that point and removes later conversation turns. Checkpoints are not version control: they may not capture changes made by terminal commands or by you outside the chat.
- Source control. Git is the real safety net. Commit before the agent starts. Then the source control view shows every changed file with a diff, and
git restore <file>orgit stashtakes you back to the known state.
A review routine
- Commit or stash your own work before the run.
- When the run ends, open the changed-files list. Note any file you did not expect.
- Review tests first, then the source files. Check for loosened assertions.
- Keep good hunks, undo bad ones, and ask the agent for a fix on the rest.
- Run the checks. Commit the kept work in a small, named commit.
- If the direction is wrong, restore: use a checkpoint for chat-only edits, or git for everything.
Before and after
Weak: the run ends, you click "Keep all", and run the app. Something breaks and you cannot tell which of fourteen edits caused it.
Better: you keep the model and route files, undo the form change, and commit those two. The form is a separate follow-up prompt. When the form breaks, the history shows exactly what changed and when.
git status --short # which files changed
git diff src/routes # read one area at a time
git restore web/Form.tsx # drop one bad file
What goes wrong
- Keep all by habit. You skip the review that the keep step exists for.
- Trusting a checkpoint too far. It restores edited files, but a package installed by a terminal command stays installed.
- Undo that loses your own work. If you edited the same file by hand during the run, a blunt restore can discard those edits.
- No commit before the run. Without a clean base, you have nothing certain to return to.
Examples
Keep two, undo one
An agent changes the model, the route and the form. The model and route diffs are right. The form diff rewrites a validation rule you did not mention. You keep the first two, undo the third, and commit. Then you ask for the form change again with a tighter prompt.
Checkpoint is not enough
You restore a chat checkpoint after a bad run. The edited files go back, but the agent had also run npm install left-pad-ng in the terminal. The package.json change is gone, yet node_modules still holds the package. git status and a clean install show the real state.
Key points
- Pending agent edits are a draft: review them per file and per hunk before choosing Keep.
- Checkpoints rewind chat edits but are not version control and can miss terminal side effects.
- Commit or stash before the run so git gives you a known good state to return to.
- Review tests first, then source, and commit the kept work in a small commit.
- If the direction is wrong, restore and re-prompt instead of patching on top of a bad change.
Common mistakes
- Clicking Keep all without opening the changed files.
- Starting a run with uncommitted work, so there is no clean state to restore.
- Assuming a chat checkpoint also undoes terminal commands and manual edits.
- Editing the same file by hand while the agent is still working on it.
Check yourself · 2 of 3
You restore a chat checkpoint, but a package the agent installed is still on disk. Why?
Check yourself · 3 of 3
An agent changed three files. Two are correct and one is wrong. What is the best move?
Practice items, not counted towards your mastery.
Start here
- Build with AI in VS Code (opens in a new tab)DocsFree
An overview of inline suggestions, chat and agents in one editor, with the controls for each.
- Add context to chat (VS Code docs) (opens in a new tab)DocsFree
How to attach files, symbols and other context so the agent answers from the right code.
- Review AI code edits (VS Code docs) (opens in a new tab)DocsFree
Keep and undo controls, and what restoring a chat checkpoint does and does not undo.