The Git Rescue Kit for AI Coding
The short version
Your AI changed the wrong thing. Before asking it to fix the fix, find out what moved. A list of changed files and a view of the changed lines usually tell you more than another long prompt.
The way back depends on where the mistake lives. Unfinished work can go on a local shelf. A change already saved in your project history needs a new change that reverses it. This kit gives you four commands, three prompts, and a small practice example so you can tell those situations apart.
Copy these prompts
Use these with an AI coding assistant that can inspect your project. Start with the first prompt. The second and third are different recovery paths; choose the one that matches what the assistant finds.
1. Inspect the change before fixing it
Inspect my current Git state without changing any files. Show me the changed-file list, the unstaged diff, the staged diff, and any new files. Explain which changes match my request and which look unrelated. Identify whether the mistake is still unfinished work or already saved in a commit. Keep sensitive values out of your summary. Do not perform a recovery action yet.
2. Put unfinished work somewhere recoverable
I want to park this unfinished AI edit and inspect the last committed version. First check for unrelated work, new files, ignored files, submodules, and unresolved conflicts. Explain what git stash push -u would preserve and what it would leave behind. Propose the smallest safe scope and wait for my approval before changing anything. After approval, show me the stash entry, the resulting file status, and how to restore it without deleting the saved stash.
3. Reverse a mistake already in history
The mistake may already be committed. Inspect the recent history and show me the exact commit and diff you propose reversing. Check that the working tree is clean and whether the commit is a merge. Explain what git revert would change and whether later work depends on it. Wait for my approval before running it. If conflicts appear, stop and explain them. Afterward, run the relevant checks and show the new reversal commit. Do not rewrite history or deploy.
Four commands, four jobs
These examples assume an existing Git repository with at least one baseline commit. They describe local source files. They do not reverse payments, database changes, or actions already taken by a running service.
Inspect: git status
git status --short
This lists changed paths and their state. In short output, the first status column describes the staging area and the second describes the working tree. ?? marks an untracked path. A changed-file list does not tell you whether the changes are correct; open the diff next.
Compare: git diff
git diff
git diff --staged
The first command compares unstaged tracked changes with the staging area. The second compares staged changes with the current commit. Newly created untracked files need their own inspection; they do not appear in these ordinary diffs.
Here is the deliberately invented example from the reel:
- export const price = 19;
+ export const price = 190;
The assignment was to tidy up a page. That extra zero changes the price. Spotting it before another edit is the useful part.
Park unfinished work: git stash
git stash push -u -m "AI draft to review"
git stash list
git status --short
-u includes untracked files alongside tracked changes. Ignored files are excluded. This example shelves all eligible changes in the repository, so inspect for unrelated work first. A stash is stored locally; it is not a remote backup. Submodule working directories need separate attention.
To apply the most recent stash while keeping the stash entry:
git stash apply
Applying can conflict with later work. Inspect the result before deleting a stash. Ordinary apply does not promise to restore the previous staged state; restoring that state requires --index and can also fail.
Reverse a committed mistake: git revert
First inspect the last commit:
git status --short
git log -1 --oneline
git show --stat HEAD
git show HEAD
If the working tree is clean and that last ordinary commit is the exact change you want to reverse:
git revert --no-edit HEAD
This creates a new commit reversing the selected commit. The original history stays visible. It does not mean every broken application is one command away from working: the wrong commit, a merge commit, dependent later changes, or conflicts need a more specific plan.
If a revert stops with conflicts and you decide to return to the pre-revert state:
git revert --abort
A five-minute practice run
Use a disposable practice repository, with no work you need to keep. Save a tiny file containing price = 19 as the baseline commit. Change it to price = 190 and add a new notes file. Inspect with status and diff. Shelve the changes with stash and confirm the baseline file is back and the new file is saved in the stash.
For the separate committed-work scenario, make and commit the price change again. Inspect that commit, then revert it. Confirm the price is back to 19 and history contains both the mistake and its reversal. Stash and revert are two branches of this exercise, not a recovery sequence to paste into an unfamiliar project.
Steal this for your app
Before a large AI edit, make a reviewed checkpoint. After it, inspect the changed-file list and the diff before requesting more changes. Keep one intention per commit so a future reversal has a clear target. After a recovery, check the application behavior as well as the Git status.
The habit is simple: inspect first, choose the recovery path second, verify the result third.
Official command references
Run this on your codebase
Audit how recoverable my next AI coding change would be. Report before fixing:
1. Is this a Git repository with a usable baseline commit?
2. Which changes are unstaged, staged, untracked, or ignored?
3. Is any unrelated work mixed into the current change?
4. Where is the last known good checkpoint, and what evidence supports that choice?
5. Would recovery mean shelving unfinished work or reversing a specific commit?
6. What could conflict, and which external effects would Git recovery leave untouched?
7. What checks would prove that recovery worked?
Give me a short recommended plan with exact commands and their scope. Do not change files, drop stashes, rewrite history, or deploy without my approval.