Fix: Cursor Overwrote or Lost Your Code Changes
Quick Answer
Press Cmd+Z repeatedly in the affected file. If that doesn't restore it, check: git diff to see changes, git stash to save current state, then git checkout -- <file> to restore from last commit.
Quick Fix Summary
| Issue | Lost my code changes |
| Fastest fix | Undo immediately |
| Use this page if | Cursor replaced your custom code with generated code |
Symptoms
- !Cursor replaced your custom code with generated code
- !Your manual edits disappeared after a Composer run
- !Entire file contents were replaced with something different
- !Hours of work gone after accepting AI changes
Step-by-Step Fix
Undo immediately
Press Cmd+Z (Mac) or Ctrl+Z (Windows) up to 100 times. VS Code/Cursor keeps a deep undo history even for AI-generated changes.
Check git reflog
Run: git reflog. This shows every state your repo has been in. Find the commit before the AI edit and run: git checkout [commit-hash] -- path/to/file
Use Local History
Cursor (like VS Code) keeps local file history. Right-click the file tab > 'Open Timeline'. You can restore any previous version from the timeline.
Set up auto-commit
Install the 'Git Auto Commit' extension or add a pre-Composer habit: always run 'git add -A && git commit -m save' before asking the AI to make changes.
Frequently Asked Questions
Yes — use Cursor's Timeline feature (right-click tab > Open Timeline). It keeps file history even without Git commits. This is your last resort for uncommitted work.
Commit before every AI edit. It takes 3 seconds: git add -A && git commit -m 'save point'. This gives you a guaranteed restore point.
Related
Weekly Signals
Get the next fix, switch, or warning before it hits your build.
Join builders getting the community signals, fix patterns, and tool shifts that matter before they show up everywhere else.
Follow the signals →