← All guides

Cursor or Windsurf agent broke your app? Undo it with git

CursorWindsurf

The agent was supposed to fix one bug. Instead it rewrote six files, deleted a component you liked, and now the app won’t start. Or it ran a terminal command you didn’t read, and your changes from this afternoon are gone. Or a Cursor Cloud Agent pushed a branch and opened a pull request on GitHub that you never wanted.

You can still get the app back. This guide goes from the gentlest undo to the fullest: the editor’s checkpoints, its local file history, then git. It also covers how to remove Cursor’s GitHub access when a Cloud Agent is the problem, plus habits that make the next bad run a quick fix.

First, stop prompting

It’s tempting to ask the agent to fix what it broke. Resist for a moment: each new run changes more files and can bury the version you want back.

Do three things before anything else:

  1. Stop the agent if it’s still running.
  2. Don’t run any command it suggests to “clean up”, especially anything with reset, checkout, clean or rm in it.
  3. Look before you undo. If the project uses git, the read-only commands under See exactly what changed show what the agent touched without changing anything.

Option 1: the built-in checkpoint

Both editors keep their own snapshots of agent work. When the damage happened in the current conversation, a checkpoint or revert is the fastest undo.

Cursor: Restore Checkpoint

Cursor’s Agent docs describe automatic checkpoints taken ahead of large edits, covering every file the agent touched (Cursor Agent docs). To go back:

  • Select a checkpoint on the chat timeline, preview that file state, then restore.
  • Or use Restore Checkpoint on an earlier request, or the + control that shows when you hover a message.

Cursor’s troubleshooting help says the same path: hover a prior message and choose Restore Checkpoint so later Agent edits drop away (Cursor agent troubleshooting).

Two things to know:

  • Restoring reverts files only. The chat messages stay in the conversation.
  • Checkpoints live on your machine, outside Git history. Cursor reserves them for rolling back Agent edits; keep Git as the lasting record.

Windsurf / Devin Desktop: revert

The editor formerly branded Windsurf is now Devin Desktop. Cognition’s changelog states that Cascade has been removed and that Devin Local is the agent available in Devin Desktop (Devin Desktop changelog, v3.9.19). Devin Local is also documented as the primary local agent (Devin Local overview).

For Devin Local sessions:

  • In Devin Desktop, the v3.7.16 changelog notes that revert controls show up once you send a prompt, and a mid-run revert stops the active turn before rolling files back (Devin Desktop changelog, v3.7.16).
  • In the Devin CLI (the same harness), list steps with /steps, then /revert <step> to put files back to that step and move the chat history to just before it (Devin CLI commands).

Older Cascade docs still describe the legacy flow: hover the prompt you want, use the revert arrow (or the conversation table of contents), and the codebase returns to that step. Those docs warn that reverts are currently irreversible, and they also mention creating a named checkpoint inside the chat (Cascade (legacy)). Prefer a git commit before you revert if you want a way back.

When the checkpoint doesn’t help

A checkpoint or revert may not be enough if:

  • the damage happened in an earlier conversation you’ve since closed or lost track of
  • the agent ran a terminal command (deleting files, a git command) rather than editing files directly
  • you edited files by hand after the agent did, and don’t want to lose those edits
  • a Cursor Cloud Agent pushed changes to GitHub (local checkpoints never saw that work)

Option 2: Local History in the Timeline view

Check whether your editor shows a Timeline panel in the Explorer sidebar. VS Code documents Timeline as the place that lists a file’s past events — git commits and local saves among them (VS Code: Timeline view).

Open the broken file, expand Timeline, and you can compare an older entry with the current file, or restore it. If a file was deleted, use the Timeline menu command that searches local history entries for a version to bring back (VS Code labels it under Local History).

It works one file at a time, and it’s a lifeline when the project has never used git.

Option 3: git

Git is the reliable layer, independent of the chat and the editor. Here it is from safest to strongest.

See exactly what changed

None of these change anything:

git status               # changed and new files
git diff --stat          # how many lines changed in each file
git diff                 # unstaged changes, line by line
git diff --staged        # changes already staged with git add
git log --oneline -10    # the last 10 commits

Save the current mess before undoing anything

Even if the current state is broken, it might contain a few good changes. Park it on a branch so nothing is lost:

git switch -c broken-agent-run
git add -A
git commit -m "Snapshot of agent changes before recovery"
git switch -

The last command takes you back to the branch you were on, at your last good commit. The agent’s work is saved on broken-agent-run, so you can copy pieces from it later, and your own branch is clean again.

Undo uncommitted changes with git restore

If the agent only changed files and didn’t commit, git restore puts them back to your last commit (git-restore):

git restore src/components/Header.tsx   # one file
git restore .                           # everything in the current folder

Want to keep some of the agent’s edits and drop others? Use patch mode, which walks you through each change:

git restore -p .

To pull one file back from an older commit without touching anything else:

git restore --source=abc1234 src/lib/api.ts

Two cautions. git restore permanently discards the uncommitted changes it overwrites, which is why the snapshot step above is worth the ten seconds. And it doesn’t remove new files the agent created. git status lists those as untracked, and you can delete the ones you don’t want after checking them.

Undo a commit with git revert

If the agent (or you) already committed the bad change, git revert creates a new commit that reverses it (git-revert). History stays intact, which makes it the safe choice for anything already pushed or shared:

git log --oneline -10
git revert abc1234

To revert several commits, list them, or give a range. Git’s docs note that revert needs a clean working tree, so commit or restore first.

Find “lost” work with git reflog

Did a reset, a rebase or a branch switch make commits vanish? They’re still there for a while. The reflog records when branch tips and HEAD moved in your local repository (git-reflog):

git reflog

Each line has an entry like HEAD@{3}, meaning “where HEAD was three moves ago.” Once you spot the commit you want, put it on a new branch so you can look at it safely:

git branch rescued HEAD@{3}
git switch rescued

Git’s docs say unreachable reflog entries are pruned after 30 days by default (90 days for reachable ones), so don’t wait months.

Check the stash

If the agent ran git stash, your changes were put aside, not deleted (git-stash):

git stash list
git stash show -p stash@{0}
git stash apply stash@{0}

apply brings the changes back and keeps the stash entry, so you can try again if it goes wrong.

About git reset —hard

Agents like to suggest git reset --hard. Git’s reset docs warn that --hard replaces the working tree with the chosen commit, can wipe untracked files, and drops tracked paths that the target commit does not contain (git-reset).

In plain terms: uncommitted changes you never staged are gone for good. Committed work can still be found with git reflog for a while.

If you do decide to use it, make it safe first:

git branch backup-before-reset    # keeps a pointer to where you are now
git stash push -u -m "before reset"   # saves uncommitted and untracked changes
git reset --hard abc1234

For uncommitted file edits, git restore does the job; for commits, use git revert — both without the risk of --hard.

Remove Cursor’s agent from a GitHub repo

If the goal is removing Cursor’s GitHub access rather than undoing file edits: Cursor’s Cloud Agents (formerly Background Agents) use the Cursor GitHub App to clone a repo you authorize, work on their own branch, push, and open a pull request that waits for your review (Cloud Agents, Cloud Agent security). Removing access stops new agent pushes; it does not reverse commits or PRs already on GitHub. Use the git sections above (or close the PR) for that.

Disconnect GitHub in Cursor

Cursor’s GitHub integration docs say the Cursor GitHub app connects repositories for features such as Cloud Agents and Bugbot. To disconnect on the Cursor side: open Integrations in the Cursor dashboard and click Disconnect Account (Cursor GitHub integration).

That breaks the Cursor ↔ GitHub link for that Cursor account. For a full stop on GitHub’s side, also review the installed app and any authorization below.

Review, limit, or uninstall the Cursor GitHub App

On GitHub, installed apps and authorized apps are different controls (installed GitHub Apps, authorized GitHub Apps):

Installed GitHub Apps (repo access the installation holds):

  1. For a personal account: profile picture → Settings → Applications (under Integrations) → Installed GitHub Apps.
  2. For an organization: organization Settings → GitHub Apps under Third-party Access.
  3. Next to Cursor, click Configure.
  4. Under Repository access, switch to Only select repositories and drop the ones you no longer want the agent to touch, then Save — or leave the install but click Suspend to block access temporarily, or Uninstall to remove the installation from that account.

Authorized GitHub Apps (permission for the app to act on your behalf):

  1. Profile picture → Settings → Applications → Authorized GitHub Apps.
  2. Find Cursor and click Revoke.

Uninstalling an installation stops that app’s access to resources in that account. Revoking authorization deactivates tokens issued on your behalf. GitHub’s docs note you may need both steps if the app is still authorized elsewhere.

Close pull requests and delete agent branches

Cloud Agents hand off by pushing a branch and opening a pull request. To reject that work without merging:

  1. Open the repository on GitHub → Pull requests → open the agent’s PR → click Close pull request at the bottom (close a pull request).
  2. After the PR is closed (or merged), delete its branch from the PR page with Delete branch, or from View all branches with the delete control next to the branch name (delete a PR branch, manage repository branches). GitHub hides Delete branch on a PR when another open pull request still points at that branch.

If bad commits already landed on main, closing the PR is not enough: use git revert on those commits (see above) and push the revert.

If you never committed

This is the hard case, but not always hopeless.

  • Try the checkpoint and Timeline options first. They don’t depend on git.
  • If you staged a version with git add and it was later overwritten or reset, git may still hold the blob as a dangling object. git fsck --lost-found dumps those objects under .git/lost-found/ (git-fsck). Blobs land in .git/lost-found/other/ without filenames, so open them to see which is which. Content that is still staged isn’t dangling yet; git diff --staged shows it.
  • Check your computer’s backups, if you had any turned on.
  • Check whether the code exists anywhere else: a deployed build, a copy on GitHub, a teammate’s machine.

Once you’ve recovered what you can, run git init, commit, and keep committing.

Find the last good version with git bisect

Sometimes you don’t know which change broke things, only that it worked a week ago. git bisect does a binary search through your history: you mark one commit as bad and one as good, it checks out a commit in between, and you tell it whether that one works (git-bisect).

git bisect start
git bisect bad              # current HEAD is broken
git bisect good abc1234     # known-good older commit
# after each checkout, mark the result:
git bisect good
# or mark it broken, then finish with:
git bisect reset

When it finishes, git names the first bad commit. Then you can git revert just that one.

Guardrails so it doesn’t happen again

A few habits turn the next bad agent run into a quick undo.

  • Commit before every agent task. git add -A && git commit -m "Before agent: add search" takes seconds and gives you a clean point to restore to.
  • Let the agent work on a branch. git switch -c agent/search-feature before you prompt. If it goes badly, switch back to main and the damage stays on the branch.
  • Name a checkpoint before big requests when your editor offers one, and keep an eye on Cursor’s checkpoints in the timeline.
  • Read terminal commands before they run. In Cursor, Settings → Agents → Approvals & Execution controls this (Cursor Run Modes). Auto-review is Cursor’s recommended default: allowlisted commands run, others run in a sandbox when possible, and the rest go to a safety classifier. Run Everything runs every call without asking. Cursor also lists File-Deletion Protection, which blocks automatic deletes (such as rm) until you approve. These Run Modes cover local agents only; Cloud Agents skip that approval UI per Cursor’s docs.
  • Steer Auto-review away from destructive git. Cursor doesn’t offer a hard deny-list for terminal commands. What it offers is block_instructions in .cursor/permissions.json, plain-English hints that push the classifier towards asking you first (permissions.json reference):
{
  "autoRun": {
    "block_instructions": [
      "Any git command that discards or rewrites work, such as git reset --hard, git checkout -- ., git clean, git push --force or git rebase, should go through approval first."
    ]
  }
}

Cursor calls this “steering, not enforcement”, so commits and branches stay the real safety net. Keep git itself off a blanket allowlist: because matching uses prefixes, an entry of git would match every git command, including destructive ones.

  • Review which repos the Cursor GitHub App can access. Prefer Selected repositories over all repositories when you connect Integrations (Cursor GitHub integration).
  • Push to GitHub regularly. A remote copy survives even if your local folder doesn’t — and give Cloud Agents only the repos you intend them to touch.

Restored, but still broken?

Sometimes the undo works but the app still isn’t right, because the agent’s changes are tangled across the codebase or mixed with good work. Once you’re on a stable version, vibe coding cleanup covers tidying what the agent left behind, and AI code review vs human review explains what an automated review catches and what it misses. If a bad agent run wiped database rows rather than source files, see what to do when an AI agent deletes your database.

If it’s still broken, a vetted senior engineer can review and fix it, and show you what went wrong. Fixed price, agreed upfront. See /fix/cursor or /fix/windsurf.

FAQ

How do I undo all changes made by the Cursor agent?

Hover over the message before the agent’s changes and click Restore Checkpoint. If that doesn’t cover it, save a snapshot branch, then use git restore . for uncommitted changes or git revert for commits.

How do I stop Cursor’s agent from pushing to my GitHub repo?

Disconnect GitHub under Integrations in the Cursor dashboard (Cursor GitHub integration). On GitHub, Configure the Cursor entry under Installed GitHub Apps and Uninstall it (or narrow Repository access), and Revoke Cursor under Authorized GitHub Apps if it appears there. Closing open agent pull requests and deleting their branches stops that handoff from merging; it does not by itself block a still-installed app from opening new ones.

Will removing Cursor’s GitHub access undo its changes?

No. Disconnecting or uninstalling the app only stops further access. Commits, branches and pull requests already on GitHub stay until you close the PR, delete the branch, or git revert the commits (see Option 3: git and Remove Cursor’s agent from a GitHub repo).

How do I stop the agent from running git reset or checkout?

Avoid Run Everything mode, keep git off your allowlist, and add block_instructions to .cursor/permissions.json. They steer the classifier rather than enforce, so commit before each agent task too.

Are checkpoints a replacement for git?

No. Cursor’s docs say checkpoints are stored locally, separate from git, and that git is for permanent version control.

Comments

Add a comment

Generated for you. Click to type your own.

Required. Never shown on the page. Privacy policy.

Basic markdown: **bold**, *italic*, `code`, lists, quotes, and fenced code blocks. HTML shows as plain text.

Your draft stays on this device until you post.