Cursor agent just delete my changes by "git restore" in sandbox

Where does the bug appear (feature/product)?

Cursor IDE


Describe the Bug

When the AI agent is allowed to run terminal commands, it can execute destructive git commands (e.g., git restore Biblio/ref.bib) that silently discard uncommitted local changes in tracked files, even when the user explicitly intended to avoid touching those files.

In my case, the agent restored Biblio/ref.bib, permanently losing several new bibliography entries that were never committed and not recoverable from git history or Cursor history.


Steps to Reproduce

  1. Open a git repo in Cursor.

  2. Edit 10 tracked files (e.g., Biblio/ref.bib) and add non-trivial changes without committing.

  3. Ask the AI something like: “(the result of git status). Don’t commit (some files).”

  4. Let the AI run tools/terminal commands autonomously.

  5. Observe that the agent may run git restore (some files), reverting the file to HEAD and discarding uncommitted changes with no confirmation dialog or safety check.


Expected Behavior

  • The AI should never run destructive VCS commands (git restore, git reset --hard, git clean, etc.) on my working directory without explicit confirmation.

  • At minimum, it should:

  • Ask for confirmation when a command would discard uncommitted changes.

  • Prefer non-destructive actions (e.g., avoid staging/unstaging or just skip files) instead of restoring.

  • Provide a clear explanation of what it plans to do before executing such commands.


Screenshots / Screen Recordings


Operating System

  • MacOS 15.7.3

Version Information

  • IDE: Version: 2.3.35

For AI issues: which model did you use?

  • Auto.

For AI issues: Request ID

NA


Additional Information

This behavior caused irrecoverable data loss. There should be safeguards against AI-initiated destructive git operations on the working tree.


Does this stop you from using Cursor?

  • Sometimes – I can sometimes use Cursor, but I now have to be very cautious with AI terminal commands because of the risk of silent data loss.

Hi there!

We detected that this may be a bug report, so we’ve moved your post to the Bug Reports category.

To help us investigate and fix this faster, could you edit your original post to include the details from the template below?

Bug Report Template - Click to expand

Where does the bug appear (feature/product)?

  • Cursor IDE
  • Cursor CLI
  • Background Agent (GitHub, Slack, Web, Linear)
  • BugBot
  • Somewhere else…

Describe the Bug
A clear and concise description of what the bug is.


Steps to Reproduce
How can you reproduce this bug? We have a much better chance at fixing issues if we can reproduce them!


Expected Behavior
What is meant to happen here that isn’t working correctly?


Screenshots / Screen Recordings
If applicable, attach images or videos (.jpg, .png, .gif, .mp4, .mov)


Operating System

  • Windows 10/11
  • MacOS
  • Linux

Version Information

  • For Cursor IDE: Menu → About Cursor → Copy
  • For Cursor CLI: Run agent about in your terminal
IDE:
Version: 2.xx.x
VSCode Version: 1.105.1
Commit: ......

CLI:
CLI Version 2026.01.17-d239e66

For AI issues: which model did you use?
Model name (e.g., Sonnet 4, Tab…)


For AI issues: add Request ID with privacy disabled
Request ID: f9a7046a-279b-47e5-ab48-6e8dc12daba1
For Background Agent issues, also post the ID: bc-…


Additional Information
Add any other context about the problem here.


Does this stop you from using Cursor?

  • Yes - Cursor is unusable
  • Sometimes - I can sometimes use Cursor
  • No - Cursor works, but with this issue

The more details you provide, the easier it is for us to reproduce and fix the issue. Thanks!

I don’t think this is actually a bug, since it executed successfully. However, it could be considered a flaw that might negatively influence users.

Hey, thanks for the detailed report. I can see the screenshot, and yeah, the agent did run git restore and removed your uncommitted changes.

This is a known issue. The team is aware that the agent can sometimes run destructive git commands. Your report helps us prioritize the fix.

For now, here are a couple of workarounds:

  1. Turn off auto-run for terminal commands: Cursor Settings > Agents > disable Auto-Run Mode. Then the agent will ask for confirmation before each terminal command, and you can reject destructive ones like git restore.

  2. Commit or stash your changes before giving the agent any git-related tasks. It’s not ideal, but it helps prevent data loss.

  3. You can also add a rule in .cursor/rules like Never run destructive git commands like git restore, git reset --hard, git clean without explicit user confirmation. It’s not a guarantee, but it should reduce the chance.

Sorry your changes got lost. Let me know if you have any questions.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.