Accepting a bad Cursor suggestion can leave your code in a broken state with partial changes across multiple files. Cursor provides checkpoints, Git integration, and undo functionality to recover quickly. This tutorial shows how to use checkpoints, git reset, and targeted reverts to undo bad suggestions without losing your other work.
Undoing bad Cursor suggestions safely
Cursor's Agent mode can modify multiple files in a single operation. When a suggestion goes wrong, you need to undo it quickly without losing other work. This tutorial covers every recovery method from Cursor's built-in checkpoints to Git-based selective reverts.
Prerequisites
- Cursor installed with Git initialized
- A project with recent Cursor-generated changes to undo
- Basic Git knowledge (commit, reset, stash)
- Familiarity with Cursor's Composer panel
Step-by-step guide
Use Cursor's built-in checkpoint restore
Use Cursor's built-in checkpoint restore
Cursor creates automatic checkpoints before every Agent mode operation. Click the restore icon in the Composer panel to revert all changes from the last operation instantly.
1// In the Cursor Composer/Agent panel:2// 1. Look for the checkpoint icon (clock/restore icon)3// next to the last operation4// 2. Click it to restore all files to their state5// BEFORE the last Agent operation6// 3. This reverts all files that were modified,7// including ones you did not ask the Agent to touch8//9// Checkpoints are created automatically — no setup needed.Expected result: All files restored to their state before the last Agent operation.
Revert specific files with git checkout
Revert specific files with git checkout
If you want to keep some changes but revert others, use git checkout to restore specific files while leaving the rest untouched.
1// Terminal: Revert specific files only2git checkout -- src/services/UserService.ts3git checkout -- src/routes/users.ts45// Keep changes in these files:6# src/components/UserProfile.tsx (has good changes)7# src/hooks/useUser.ts (has good changes)89// Verify what is still modified:10git statusPro tip: Use git diff --name-only to see all modified files before deciding which to revert. This gives you a complete picture of what Cursor changed.
Expected result: Specific files reverted while other changes are preserved.
Use git stash for temporary safekeeping
Use git stash for temporary safekeeping
If you are unsure which changes to keep, stash everything first. Then selectively restore the good changes from the stash.
1// Save all current changes:2git stash push -m "before reverting cursor changes"34// Your working directory is now clean.5// Selectively apply good files from the stash:6git stash show -p | git apply --include='src/components/*'78// Or restore the entire stash if you change your mind:9git stash popExpected result: Changes safely stashed, with selective restoration of the good parts.
Revert to a specific Git commit
Revert to a specific Git commit
If you committed before the Cursor session (as recommended), you can reset to that commit. This is the nuclear option that reverts everything since the checkpoint commit.
1// Find the pre-Cursor commit:2git log --oneline -534// Soft reset preserves changes as unstaged:5git reset --soft HEAD~167// Or hard reset discards everything:8# git reset --hard HEAD~19# WARNING: This permanently discards all changes since the commit.10# Only use if you are certain you want to lose everything.Expected result: Working directory restored to the state of the selected commit.
Prevent bad merges with pre-acceptance habits
Prevent bad merges with pre-acceptance habits
Build habits that make undo easier: commit before every Cursor session, use Plan Mode for complex tasks, and review diffs before accepting.
1// Pre-Cursor session checklist:2// 1. Commit current work: git add -A && git commit -m 'checkpoint'3// 2. Start a new Cursor Chat/Composer session4// 3. Use Plan Mode (Shift+Tab) for complex tasks5// 4. Review every diff before clicking Accept6// 5. Test after accepting (compile + tests)7// 6. Commit good results immediately8//9// This gives you a clean commit to revert to if needed.Expected result: A safety workflow that makes every Cursor session reversible.
Complete working example
1#!/bin/bash2# Cursor Safety Script — run before every AI coding session3# Creates a checkpoint commit and branch for safe experimentation45set -e67# Get current branch name8BRANCH=$(git branch --show-current)9TIMESTAMP=$(date +%Y%m%d-%H%M%S)1011# Check for uncommitted changes12if [ -n "$(git status --porcelain)" ]; then13 echo "Committing current changes as checkpoint..."14 git add -A15 git commit -m "checkpoint: before cursor session $TIMESTAMP"16fi1718# Create a backup branch19BACKUP="backup/$BRANCH-$TIMESTAMP"20git branch "$BACKUP"21echo "Backup branch created: $BACKUP"22echo ""23echo "Safety checkpoint complete."24echo "If Cursor makes bad changes, run:"25echo " git reset --hard $BACKUP"26echo ""27echo "Or restore specific files:"28echo " git checkout $BACKUP -- path/to/file.ts"Common mistakes when undoing bad Cursor suggestions
Why it's a problem: Using git reset --hard without checking what will be lost
How to avoid: Use git stash first to save everything, then selectively restore. Or use git reset --soft to unstage without discarding.
Why it's a problem: Not committing before Cursor sessions
How to avoid: Run 'git add -A && git commit -m checkpoint' before every Cursor Agent session. Make it muscle memory.
Why it's a problem: Accepting changes without reviewing the diff
How to avoid: Always review the diff in Cursor's panel before clicking Accept. Check red lines (deletions) first.
Best practices
- Commit to Git before every Cursor Agent session as a checkpoint
- Use Cursor's built-in checkpoint restore for the quickest undo
- Use git checkout for selective file-level reverts
- Use git stash when unsure which changes to keep
- Review diffs before accepting to prevent bad merges entirely
- Create a backup branch before experimental Cursor sessions
- Run tests immediately after accepting changes to catch issues early
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I accepted a Cursor AI suggestion that modified 8 files but only 3 of the changes are correct. The other 5 files need to be reverted. I have not committed yet. What is the safest git workflow to keep the 3 good files and revert the 5 bad ones? Show commands for each step.
In Cursor Chat (Cmd+L): @git I accepted changes from the last Agent session but the modifications to src/services/ are wrong. The changes to src/components/ are good. How do I revert only the service files while keeping the component changes? Show the git commands.
Frequently asked questions
Does Cursor have built-in undo?
Yes. Cursor creates automatic checkpoints before Agent mode operations. Click the restore icon in the Composer panel to revert the last operation. This is the fastest way to undo.
Can I undo changes from multiple Cursor sessions ago?
Cursor checkpoints only cover the last operation. For older changes, you need Git. This is why committing before every session is essential.
Will undo affect my Git history?
Cursor's checkpoint restore does not create Git commits. It modifies files in your working directory. Git-based reverts (reset, checkout) do affect history depending on the command used.
What if I already committed bad Cursor changes?
Use git revert HEAD to create a new commit that undoes the last one. Or use git reset --soft HEAD~1 to uncommit and then selectively re-stage the good changes.
How do I avoid needing to undo in the first place?
Use Plan Mode (Shift+Tab) to review the plan before execution. Start with small, focused tasks. Review every diff before accepting. Commit after each successful step.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation