I was refactoring a settings screen late one evening when the AI finished writing close to 100 lines. Only the last line bothered me, so I pressed ⌘Z once. All 99 lines I wanted to keep disappeared with it. Asking again didn't bring back the same code, and I sat there for about twenty minutes with my hands off the keyboard.
What I worked out afterwards is that this is less a bug than a mismatch: AI edits and the classic undo stack weren't built with each other in mind. Once you know why, most of these accidents are preventable, and the rest are recoverable. A caveat before we start: Antigravity doesn't document its internals in detail, so parts of the explanation below are inference from how it behaves.
If it just vanished: stop typing and try these in order
If the code is already gone, start here and read the reasoning afterwards.
- Don't type anything. A single new edit clears the redo stack.
- Press
⌘⇧Z(Redo). Right after an undo, this often brings everything back. - If not, open the command palette with
⌘⇧P, runLocal History: Find Entry to Restore, and pick the snapshot from just after the AI finished. - Still missing? Copy the code block from the agent's previous reply in the chat history.
The recovery section further down explains each step in more detail.
Why one Cmd+Z can erase so much
VS Code-style editors merge edits made close together in time into a single undo group. When you type by hand, the groups break at characters and words, so ⌘Z steps back in small, comfortable pieces.
AI edits arrive differently. Many changes land in a very short window, and sometimes the whole file is swapped in one operation. To the editor, that looks like one person typing impossibly fast, so it forms one big undo group.
Press ⌘Z once and the whole group goes. Whether it holds 100 lines or 1,000, the editor sees it as your last single action.
The three situations that caught me most often:
- Asking the AI to rewrite an entire file
- A Manager Surface agent editing several files in one step
- Inline chat with a wide range, such as "rewrite lines 40 to 220"
If you are in one of these, assume undo won't be as gentle as it is for hand-typed code.
Three habits that prevent the wipe
Each takes about a minute to start.
1. Draw a line in Git before handing over the keyboard
The most reliable habit is to run git add -A twice: once right before a large edit, and again as soon as the AI finishes and you've looked at the result.
# 1. Before asking: freeze the pre-edit state (git diff then shows only the AI's changes)
git add -A
# 2. After the AI finishes and you've checked it: freeze the AI's output itself
git add -A
# If ⌘Z took more than you meant: write the staged content back to the working tree
git restore path/to/file.swiftI used to assume the first staging also protected what the AI wrote. It doesn't. It freezes the state from before the edit. The AI's output is only safe once the second staging (or a commit) has happened. I now think of the first as a baseline for diffs and the second as the insurance. No commit needed.
If you use task files (.antigravity/tasks/*.md), I also add a line such as "The user has staged the working tree; make small commits per logical change." It sometimes nudges the agent toward finer commits. I wouldn't call it a guarantee, but it costs nothing.
2. Use Manager Surface checkpoints
When an agent edits files, the run history in the sidebar shows a marker for each step. On my build it looks like a small flag with a "restore to this point" action; labels change between versions, so check your own screen.
Restoring from there rewinds by agent step instead of by editor undo group. You can drop exactly the change you regret and keep the rest. I now run an agent once through Manager Surface even for work I could do inline, because having somewhere to go back to takes the knot out of my stomach.
3. Ask for less at a time
Instead of "fix this whole file," go function A, then function B, then the tests. It helps quality too, since a 200-line generation tends to lose small details.
Slices of 30 to 50 lines keep undo groups small and fixes easy. It feels slower in the moment, but by the end of the day I'd usually finished sooner.
Don't count on undo settings
I used to look for a setting that makes undo finer, something like editor.undo.granularity. I couldn't confirm that name or any equivalent in VS Code's settings reference or in search results, and an earlier version of this article showed a config example I hadn't verified. I've removed it. Search "undo" in your own Antigravity settings and trust only what actually appears there.
What I can say with confidence is that a route that doesn't depend on undo is more reliable than a finer undo. For that, tune Local History, which does exist in VS Code-based editors:
// settings.json — keep Local History on (real VS Code setting names)
{
"workbench.localHistory.enabled": true,
"workbench.localHistory.maxFileEntries": 200
}Local History stores a file snapshot on each save, which the next section relies on. Pair it with files.autoSave so a save happens right after the AI's edit. Defaults can differ between versions, so check the values on your own install.
Recovering after the wipe
Try ⌘⇧Z (Redo) first. If you act immediately, it works instantly. The catch is that any other edit clears the redo stack, so when ⌘Z takes more than you meant, stop and don't type anything.
If redo is gone, open the command palette with ⌘⇧P and run Local History: Find Entry to Restore. It worked for me in Antigravity, and snapshots from before and after AI edits are often still there.
# Local History location on macOS (may differ by version)
~/Library/Application\ Support/Antigravity/User/HistoryA search like grep -r "the function name you lost" ~/Library/Application\ Support/Antigravity/User/History/ can find the right snapshot. I once pulled back 80 lines of test code this way after giving them up.
The last resort is the agent's own log. Manager Surface keeps the code it produced in the conversation, so asking "re-emit only the code block from your previous reply" usually gets it back. Undo and chat history are stored separately, which is why the history survives when the buffer doesn't.
Label the request before you send it
Not every AI edit carries the same risk. Since I started putting a quick mental label on each request, I've spent almost no time on recovery.
Single-line inline completions are close to harmless. Selecting about 30 lines for a refactor starts to build larger groups, but one or two ⌘Z presses usually sort it out. Whole-file rewrites and multi-file agent runs are the dangerous ones, and I treat them like a database migration: snapshot first.
My rule of thumb is simple. If the edit reaches beyond what's on screen, spend five seconds staging. Those five seconds are nothing next to the dread of a missing test file.
What to tell your team
If a team shares the setup, leave a short note in your playbook, and frame it as a quirk of how editors and models interact, not as someone's slip. "Be careful" alone just means the same accident happens to someone else next week.
When everyone agrees that AI edits behave differently from typing, near-misses get shared and recovery gets faster. A team that can say "that happened to me" out loud has the strongest safety net I know of.
My working rules
Before a large edit, and again right after I've checked the result, I run git add -A. I prefer Manager Surface agents to raw inline edits so checkpoints exist. Each request stays within 30 to 50 lines, and bigger refactors are split into explicit steps. Within a few minutes of an AI edit I make a throwaway git commit -m "wip: ai-edit" and tidy the history later with git rebase -i. I don't rely on undo settings; my way back lives in Git and Local History.
Make a place to return to before it writes, and when something vanishes, stop typing first. I try to keep that one rule even on tired nights.
If agent changes aren't showing up at all, the diagnostic guide for agent code changes not applied is worth a look. For rewinding only the conversation, see the undo and direct-send comparison, and for re-running work, Mastering Antigravity's Smart Retry.
Start with just one thing today: git add -A right after the AI finishes a large edit. The rest can be added one at a time as it starts to feel natural.