Git Undo Button for AI Coding
Published
Always get back to a working version when an AI edit goes wrong: tested checkpoint and undo scripts that never lose work, a pre-commit hook that blocks .env files and API keys, AI rules that forbid force-pushes and resets, and rescue playbooks for reflog, leaked keys and Vercel rollbacks.
Download free (.zip)Feedback / Report a problemFree, no sign-up. Want the week's best kits by email? Get the weekly roundup (optional).
What's in the kit
safety-net/ folder (checkpoint.sh, undo-last.sh, install.sh, PowerShell checkpoint.ps1, undo-last.ps1, install.ps1, the pre-commit hook, gitignore-starter.txt for Next.js/Vite/Supabase/Vercel), drop-in rules (AGENTS.md, CLAUDE.md, .cursor/rules/git-safety-net.mdc, .cursor/permissions.json, .claude/settings.json), 6 rescue playbooks, 10 copy-paste prompts, setup for Git, your project, GitHub, Vercel and each AI tool, checklist, guardrails, examples, troubleshooting and sources.
- checkpoint and undo-last scripts (bash + PowerShell): undo uncommitted or committed AI changes, with every undone file copied to a backup branch first
- A pre-commit hook that blocks .env and key files plus Stripe, OpenAI, Anthropic, Supabase, AWS, GitHub and other key patterns, without printing the key (runs gitleaks too if installed)
- Rules for Cursor (.mdc + Auto-review permissions), Claude Code (CLAUDE.md + permission prompts) and AGENTS.md: checkpoint first, never force-push, reset, clean or rewrite history without asking
- Rescue playbooks: undo the last AI change, recover a deleted file, reflog after a bad reset, 'I pushed a secret' (rotate first), Vercel Instant Rollback
- What Cursor, Claude Code, Lovable, Replit and Bolt checkpoints restore, and what they can't (databases, deploys, emails)
- 10 copy-paste rescue prompts that make the AI preview and wait for your yes
Free sample: Playbook: undo the last AI change
Copy it right here, or download the whole kit above. This is the actual text from the kit.
# Playbook 01: Undo the last AI change
Use this when the AI just broke something and you want the last working version back.
## Step 0: stop the AI
Press the stop button (Cursor) or `Esc` (Claude Code) so it doesn't keep "fixing". Don't ask it to fix the fix yet.
## Step 1: is the bad change committed?
In a terminal in your project folder (Git Bash on Windows):
```bash
git status
git log --oneline -5
```
- `git status` lists changed files → the change is **uncommitted**. Go to step 2A.
- `git status` says `nothing to commit, working tree clean` and the top line of `git log` is the bad change → it's **committed**. Go to step 2B.
Quicker for a change from the chat you're still in: the tool's own undo (Cursor "Restore Checkpoint", Claude Code `/rewind`, Lovable "Undo latest edit"). See [06-tool-checkpoints.md](06-tool-checkpoints.md) for what those can and can't undo. Then come back here and save a checkpoint.
## Step 2A: uncommitted change
```bash
bash safety-net/undo-last.sh # preview: lists the files, changes nothing
bash safety-net/undo-last.sh --yes # do it
```
Windows PowerShell: `powershell -ExecutionPolicy Bypass -File safety-net\undo-last.ps1` then the same with `-Yes`.
What happens:
1. Every changed, new and deleted file is copied into a backup branch named `safety-backup/undo-<date-time>`. The script checks the copy file by file before it touches anything.
2. Your files go back to the last checkpoint. New files the AI created are removed from disk (they're in the backup).
3. `.env` / key files and the `safety-net/` folder are never touched.
Changed your mind? The script prints these, with the real branch name:
```bash
git show --stat safety-backup/undo-20261123-101500 # what's in it
git restore --source=safety-backup/undo-20261123-101500 -- src/app/page.tsx # one file back
git restore --source=safety-backup/undo-20261123-101500 --worktree -- . # everything back
```
## Step 2B: committed change
```bash
bash safety-net/undo-last.sh # preview: shows the commit it would undo
bash safety-net/undo-last.sh --yes
```
It uses `git revert`: a **new** commit that reverses the bad one. Nothing is deleted from history, so it's safe even if you already pushed. A `safety-backup/before-revert-...` branch marks where you were.
- **Undo the undo:** run `undo-last.sh --yes` again right away. The preview warns you that it would redo the change.
- **It refused because it would "put a secret back":** the commit you're undoing had removed a leaked key. Use `--to` (below) to pick an older checkpoint instead, and read [04-pushed-a-secret.md](04-pushed-a-secret.md).
- **Already pushed and Vercel deployed it:** after the revert, push as normal (`git push`). For instant relief while you work, roll back on Vercel: [05-vercel-rollback.md](05-vercel-rollback.md).
## Go back several changes
```bash
git log --oneline -15 # find the last good checkpoint's hash, e.g. 3f2a1bc
bash safety-net/undo-last.sh --to 3f2a1bc # preview
bash safety-net/undo-last.sh --to 3f2a1bc --yes # files now match 3f2a1bc, saved as a new commit "undo: back to 3f2a1bc"
```
History is kept and a `safety-backup/before-goto-...` branch is made first. If you have uncommitted changes it refuses; run step 2A first.
## Only one file is broken
```bash
git log --oneline -- src/lib/auth.ts # commits that touched it
git restore --source=3f2a1bc -- src/lib/auth.ts # that file only, as it was in 3f2a1bc
bash safety-net/checkpoint.sh "restore auth.ts from 3f2a1bc"
```
## The last commit is a merge
`undo-last.sh` won't guess which side to keep. To undo a merge into your branch (often `main`; check with `git branch --show-current`) and keep that branch's side: `git revert -m 1 <merge-hash>`. Ask your AI to explain it first with the prompt in [../prompts.md](../prompts.md).
## Without the scripts (plain git)
- Uncommitted: `git stash push --include-untracked -m "before undo"` saves everything and cleans the folder. Get it back with `git stash list` and then `git stash apply stash@{0}`. Never `git stash drop` it until you're sure.
- Committed: `git revert --no-edit HEAD`. Note: **`git revert` doesn't run the pre-commit hook**, so check `git show --stat HEAD` for `.env` or keys before you push. (`undo-last.sh` does that check for you.)
## Never do these to "undo"
`git reset --hard`, `git clean -fd`, `git checkout .`, `git push --force`. They throw work away or rewrite shared history. If one already happened: [03-bad-reset-reflog.md](03-bad-reset-reflog.md).
Questions about this kit
Is the Git Undo Button for AI Coding kit free?
Yes. It's a free .zip download ($0) with no account and no email required. Bot Pantry is paid for by clearly labeled sponsors, not by selling kits.
Who is this kit for?
Beginners and vibe coders who let AI tools edit their code and want a guaranteed way back to a working version, no leaked keys in git, and a plan for a bad Vercel deploy.
Which tools does it work with?
It's written for: Git; GitHub; Vercel; Cursor; Claude Code; Lovable; Replit; Bolt; v0; gitleaks (optional). The kit is a .zip of files (prompts, templates, guides and checklists) that you use with those tools. Bot Pantry has no app or account to sign up for.
How long does setup take?
About 20-50 min. That setup time was checked when the kit was reviewed before publishing.
How do I start?
Download the .zip, unzip it and open README.md first. It explains what each file is for and walks you through setup (about 20-50 min). The free sample above is a real file from the kit.
Will the AI act on its own?
No. Like every Bot Pantry kit, it is set up so the AI drafts or suggests and you decide. It should not send, post, delete or spend anything on its own.
More free kits for vibe coders
Free AI agent kits for vibe coders · Browse the full kit library
Where this kit fits: Vibe coding launch checklist: 4 free kits, in order