---
title: "How to undo one AI edit and keep the rest"
author: Pedro Thomaz
source: https://coffeetext.app/blog/undo-one-ai-edit
---

# How to undo one AI edit and keep the rest

> Checked November 2026 against the Git, Claude Code and Cursor documentation linked below. Coffee isn't affiliated with any of them.

With Git, run `git restore -p notes.md` and answer `y` only for the block you want gone. Before an edit lands, Claude Code's VS Code extension lets you reject a single change in its diff. Coffee shows each change as a card with its own Undo. Avoid a rewind for this job, because rewinds in both Claude Code and Cursor take you back to a point in the session and remove everything after it.

Which one you need depends on where the edit is now, so here they are side by side.

| Where you are | What to use | What it undoes |
|---|---|---|
| Edit is on disk, not committed | `git restore -p` | The blocks you pick |
| Edit is proposed in VS Code, not yet applied | Reject this change | One change |
| Edit applied in Cursor | Reject in the diff view | What you reject |
| Edit was committed | `git restore -p -s HEAD~1` or `git revert -n` | The blocks you pick, or the whole commit |
| No Git, file open in Coffee | Undo on a card | One change |
| No Git and no earlier copy | Ask the tool, or fix it by hand | Whatever you can identify |

## With Git, before you commit

Git calls a block of changed lines a hunk, and [`git restore -p`](https://git-scm.com/docs/git-restore) walks through them one at a time, asking whether to discard each:

```
git diff --word-diff notes.md   # see what changed
git restore -p notes.md         # choose what to discard
```

[The keys are the same as for `git add -p`](https://git-scm.com/docs/git-add). `y` takes the action on this hunk and `n` leaves it. `s` splits a hunk into smaller ones, `e` lets you edit it by hand, and `q` stops. Press `?` to see the list at any time.

Be careful with the meaning here, because `y` in `git restore -p` means discard. If that feels backwards, do it the other way round: stage what you want to keep, then throw away the rest.

```
git add -p notes.md     # y for each change you want to keep
git restore notes.md    # discard everything you didn't stage
```

This works because `git restore` restores from the staged copy by default. Then commit, and you have the version you wanted.

## With Git, after you commit

If the edit is already in a commit, the same approach works with a source. This offers the blocks that differ from the commit before:

```
git restore -p -s HEAD~1 -- notes.md
```

Then commit the result.

To reverse a commit as a whole, [`git revert`](https://git-scm.com/docs/git-revert) records a new commit that undoes it, which keeps the history honest. With `-n` it makes the changes without committing, so you can adjust the result first. It needs a clean working folder.

## The problem with prose

All of this works by lines, and that's a poor fit for writing. A paragraph of Markdown is often one long line, so if a tool changed one word in it, the hunk is the whole paragraph. Adjacent changed lines also tend to travel together in one hunk.

You have three ways round it:

- **Press `s`** to split a hunk, which helps when unchanged lines sit between the changes.
- **Press `e`** to edit the hunk directly, which gives you full control and takes some care.
- **Undo nothing and fix it by hand.** Run `git diff --word-diff`, find the word, and put it back. For a single wrong number in a long paragraph, this is usually quickest.

If you write with one sentence per line, hunks get smaller and all of this gets easier. In standard Markdown, a single line break stays inside the same paragraph, so the page reads the same.

## In Claude Code

Its [VS Code extension](https://code.claude.com/docs/en/vs-code) can do this before anything is final. In Manual mode, it shows the original and the proposed text side by side. Under each change there are Accept this change and Reject this change buttons, and you can also edit the proposal directly in the diff before accepting. That needs Claude Code v2.1.275 or later, and a diff with more than 100 changes opens as a whole file instead.

[`/rewind`](https://code.claude.com/docs/en/checkpointing) works differently. You choose a prompt and restore from there, so it undoes everything after that point rather than one edit in the middle. It's the right tool if the last prompt went wrong as a whole. If you want to keep some of it, you'll need Git or a word to Claude.

Telling it works too: "undo the change you made to the second paragraph and leave the rest." That's a fresh edit rather than a real undo, so it's worth checking the diff afterwards.

## In Cursor

[Cursor's help](https://cursor.com/help/ai-features/agent) says Agent applies its edits as it works, and that you review them in the diff view and reject what you don't want. That page doesn't spell out whether rejecting works per file or per change, so see what your version offers.

Restore Checkpoint is the rewind equivalent. Hover over an earlier message and it rolls back everything Agent did after that, affecting files and leaving the conversation alone.

## In Coffee

Coffee doesn't need the tool's cooperation or a repository. When a note differs from how you last read it, a bar tells you how many changes there are. Press Review and each one appears as a card with the old text, the new text and the heading it falls under. Undo reverses that one and leaves the others.

*There's a working demo of this [on the page](https://coffeetext.app/blog/undo-one-ai-edit).*

Undo is an ordinary edit, so ⌘Z brings it back. Keep accepts one change, and Keep all and Undo all deal with the rest. It works with any tool that edits the file, as it only looks at the file itself.

It has the same line problem as Git. A changed paragraph shows as an old paragraph and a new one, so Undo takes back the whole paragraph, and the changed word isn't highlighted. To keep most of a rewritten paragraph, undo it and retype the good part, or copy from the card first. It also needs an earlier read to compare with, so changes to a note you've never opened in Coffee don't show. Private notes are skipped. [The full list of limits](https://coffeetext.app/blog/review-claude-cursor-markdown-changes) is in the review guide.

## So the next one's easier

Commit before each round, and ask for one kind of change at a time. If "fix typos" and "shorten the intro" arrive as separate commits, `git revert` can take away one and leave the other, and you've avoided most of the fiddly work above. There's more in [keeping AI tools from wrecking your notes](https://coffeetext.app/blog/keep-ai-from-wrecking-notes).

## Questions

### What does git restore -p do?

It goes through each changed block in a file and asks whether to discard it. `y` discards that block, `n` keeps it. It needs Git and a file Git is tracking.

### Why can't Git undo just one word?

Git's hunks work by lines, and a Markdown paragraph is often one line. Use `e` to edit the hunk by hand, or fix the word yourself after finding it with `git diff --word-diff`.

### Does Claude Code's rewind undo a single edit?

No. It restores to a prompt you choose and removes the file edits made after it. To reject single changes, use the per-change buttons in the VS Code extension before accepting.

### Can I undo one AI edit without Git?

Yes, if you have something to compare with. Coffee keeps the note as you last read it and lets you undo one change at a time. Otherwise, ask the tool to reverse it, or fix it by hand.

### I undid the wrong thing. Now what?

In Coffee, ⌘Z brings it back while the note is open. `git restore` discards uncommitted changes with no undo of its own, which is why committing first, or using the `git add -p` route, is the safer habit.

---

Written by Pedro Thomaz, who makes Coffee, a Markdown editor for the Mac on macOS 15 or later. It's free for 14 days with no card or account, then €3 a month, €29 a year, or €79 once with two years of updates. More at https://coffeetext.app/llms-full.txt
