The phrase "undo my changes" is too ambiguous for this task. It can mean removing a file from the next commit, discarding local text, or reversing a committed change. Those operations affect different versions of the file.
Name the three versions
This original teaching scenario has a tracked notes.txt:
| Location | Contents before the operation | Intended contents afterward |
|---|---|---|
| HEAD, the current commit | A: initial note | A: initial note |
| Index, the staged version | B: initial note plus heading | A: initial note |
| Working tree, the file on disk | C: heading plus an additional paragraph | C: heading plus an additional paragraph |
The desired operation removes B from the next commit proposal while preserving all of C. The official Git restore reference, checked October 24, 2026, distinguishes --staged from restoring the working tree. With --staged, the default source is HEAD. Without it, a plain restore normally restores the working file from the index, which would overwrite unstaged changes.
That difference is why a suggestion containing only git restore notes.txt would be wrong for this goal. Do not add --worktree to an unstage-only request.
Inspect both comparisons first
Run these read-only commands in the intended repository:
git status --short
git diff --cached -- notes.txt
git diff -- notes.txt
The cached diff compares the index with HEAD. The other diff compares the working file with the index. Read both; one command alone can hide one of the changes you want to preserve.
If the path is untracked, conflicted, deleted unexpectedly, or the repository has no initial commit, stop applying the three-version scenario mechanically. Supply that actual state. A path beginning with a dash also needs the -- separator shown here so Git treats it as a path.
Ask for the effect before accepting the command
Help explain one Git operation before I run it.
Git version and OS/shell: [ENTER]
Repository state, including whether HEAD exists: [ENTER]
Exact tracked path: notes.txt
git status --short: [PASTE]
git diff --cached -- notes.txt: [PASTE PERMITTED DIFF]
git diff -- notes.txt: [PASTE PERMITTED DIFF]
Goal: remove this file's staged changes while preserving every current
working-file edit. Do not change any other path.
Explain HEAD, index and working-tree contents before and after your
proposed command. State the restore source and destination. Give one
path-scoped command and read-only checks. If the actual state differs
from a normal tracked file with HEAD, ask before proposing a mutation.
Do not execute commands, discard edits, commit, reset broadly or push.
OpenAI's prompting documentation supports giving context, the intended result and constraints. Here, preserving the working-file version is the requirement that should control the answer.
Check the resulting state
For the stated ordinary tracked-file scenario, the one operation is:
git restore --staged -- notes.txt
Repeat the status and both diffs. The cached diff for this file should now be empty. The working diff should contain the full change from A to C, including the heading that was previously staged and the additional paragraph. This is a predicted result for the teaching state, not a record of a command run in your repository.
Read the actual file too. Once you have confirmed that the intended text survived, decide which changes belong together before staging again. The code-review guide addresses the separate question of whether those code changes behave correctly.