AI broke your project. Here's how to get your working app back.
By Carl Mills - senior engineer • Published 9 July 2026 • Last updated
TL;DR
Stop prompting. Every "please fix it" makes the hole
deeper. Recovery, in order: (1) uncommitted AI mess → git stash;
(2) bad commits → git log --oneline then
git reset --hard <last-good>; (3) "it's all gone" →
git reflog - git remembers everywhere your project has been for ~90 days;
(4) no git at all → editor local history (VS Code Timeline), Cursor checkpoints,
or your last deployed build. Then set up the 3-command safety net below so this never
costs you a day again.
First: stop digging
When an AI session goes wrong, the instinct is to keep prompting: "that broke it, fix it". Each attempt rewrites more files, and the model is now reasoning about its own broken output. The working version drifts further away with every message. Close the loop: your job for the next ten minutes is recovery, not repair.
Scenario 1: the AI's changes aren't committed yet
Check what state you're in:
git status
If you see modified files and you want them gone but recoverable:
git stash
Your project instantly returns to the last commit; the AI's changes are parked (get them back
later with git stash pop if any were useful). If you're certain you want the
changes discarded permanently: git checkout -- .
Scenario 2: the session made commits
See the history and spot where things were last good:
git log --oneline -15
Test your guess without losing anything - this moves you there temporarily:
git checkout <commit-hash>
# run the app, confirm it works
git checkout - # jump back
When you've confirmed the last good commit, return the branch to it:
git reset --hard <commit-hash>
Prefer keeping the broken history for forensics? Use
git revert <bad-commit>..HEAD instead - same result, nothing deleted.
Scenario 3: "I reset something and now it's ALL gone"
This is the one that feels unrecoverable and almost never is. Git keeps a private journal of every position your repository has held - resets, rebases, deleted branches included:
git reflog
You'll see entries like HEAD@{7}: commit: payments working. Found the good one?
Rescue it onto a fresh branch (safest - changes nothing else):
git branch rescue HEAD@{7}
git checkout rescue
Reflog entries survive for roughly 90 days by default. If the code ever existed in a commit, it is almost certainly still in there.
Scenario 4: there is no git repository
Common with one-click AI builders. Your options, best first:
| Source | Where to look | Gets you |
|---|---|---|
| Editor local history | VS Code: file → Timeline panel. JetBrains: right-click → Local History | Per-file versions from the last days |
| AI tool checkpoints | Cursor: "Restore checkpoint" in the session; Lovable/Bolt: version history panel | Whole-project snapshots per prompt |
| Deploy platform | Vercel/Netlify/Azure: deployments list → rollback or download build | The last version that actually worked in public |
| Cloud sync | OneDrive/Dropbox/Time Machine version history | Whatever was synced, file by file |
Recovered? Your first action with the working copy: git init && git add -A
&& git commit -m "working version". You never want to read this section twice.
The 3-command safety net (do this today)
AI coding multiplies how fast you change code, so it multiplies how much a missing checkpoint costs. The habit that fixes it permanently:
- Before every AI session:
Five seconds. This single habit removes 90% of the pain in this guide.git add -A && git commit -m "checkpoint: before AI session" - Let the AI work on a branch:
Main stays working; a bad session gets deleted, not untangled.git checkout -b ai/feature-name - Push somewhere:
A free private GitHub repo means your safety net survives a dead laptop.git push -u origin main
Tools help too: Claude Code proposes commits as it works, and Cursor keeps automatic checkpoints - but tool checkpoints live inside the tool. Git is yours.
Frequently asked questions
Can I ask the AI to fix what it broke?
After you've recovered a working baseline, yes - in a fresh session, on a branch, with the specific error pasted in. Asking a confused session to un-confuse itself is how a bad hour becomes a bad day.
Does git reflog work after git reset --hard?
Yes - that's exactly what it's for. Reset moves your branch; reflog remembers where it was. Uncommitted changes, however, are not in reflog: only committed work is fully protected.
How often should I commit during AI sessions?
Every time the app works and the change is coherent - typically every 15-30 minutes of AI pairing. Think of commits as save points in a game you're playing against entropy.
I'm not a developer - is learning git worth it just for this?
You need six commands, all on this page. An afternoon with them is cheaper than losing one working app - and every AI tool works better inside a git repository anyway.
Keep going
- App recovered and heading for launch? Run the 12-point security checklist first.
- New to git? Our free CLI & GitHub articles cover the fundamentals step by step.
- Project too tangled to rescue yourself? A short recovery engagement is a thing we do - usually a day.