#github-copilot#recovery#undo#ai-coding#vs-code

GitHub Copilot Deleted My Code: How to Recover

Lost code to a GitHub Copilot suggestion? Here's how to recover deleted files and undo unwanted changes from Copilot in VS Code.

You accepted a GitHub Copilot suggestion and now your code is broken. Or worse, Copilot Edits just rewrote half your project and you need it back the way it was.

Here’s how to recover, depending on what happened.

Immediate Undo: Ctrl+Z / Cmd+Z

If you just accepted a Copilot suggestion, hit undo immediately:

  • Windows/Linux: Ctrl+Z
  • Mac: Cmd+Z

This works for inline completions and single-file edits. The limitation is that each file has its own undo history, so multi-file changes require undoing in each file separately.

If you’ve made other edits since accepting the suggestion, you may need to undo multiple times to get back to the right state.

VS Code Local History

VS Code automatically saves versions of your files as you work. This is your best friend for Copilot recovery.

To access Local History:

  1. Press Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows/Linux)
  2. Type “Local History: Find Entry to Restore”
  3. Select the file you want to recover
  4. Browse through previous versions by timestamp
  5. Click to restore

This works even for deleted files, as long as VS Code had the file open at some point.

Pro tip: You can also right-click any file in the Explorer and select “Open Timeline” to see its version history.

Git Recovery

If you committed before accepting the Copilot suggestion, Git makes recovery easy:

# See what changed
git diff

# Discard all uncommitted changes
git checkout .

# Or restore a specific file
git checkout HEAD -- path/to/file.ts

If you accidentally committed the bad changes:

# Undo the last commit but keep changes staged
git reset --soft HEAD~1

# Or completely remove the last commit
git reset --hard HEAD~1

The catch: this only works if you committed before Copilot made changes. If you were iterating quickly without commits, Git can’t help.

Recovering from Copilot Edits

Copilot Edits (the multi-file editing feature) can make sweeping changes across your codebase. When it goes wrong, you need to recover multiple files at once.

Your options:

  1. Git stash/checkout: If you have a clean commit, git checkout . reverts everything
  2. Local History: Recover files one by one (tedious for many files)
  3. Copilot Edits history: In the Copilot Edits panel, you can sometimes see previous edit sessions

For Copilot Edits, the best protection is making a commit before starting an edit session. A quick git commit -am "before copilot edits" takes 2 seconds and saves hours of recovery.

The Automatic Approach

All these recovery methods require you to do something: commit before changes, access Local History, remember to undo quickly.

mrq takes a different approach. It watches your project and captures every file change automatically:

npm install -g mrq-cli
mrq login
mrq watch

Now every change is captured, whether from Copilot, manual edits, or any other source.

When Copilot breaks something:

mrq history          # See recent snapshots
mrq restore abc123   # Restore to any point

No commits to remember, no Local History to dig through. Every state is recoverable.

Prevention Tips

A few habits that make Copilot safer:

  1. Review before accepting: Read the suggestion, don’t just Tab through
  2. Use Copilot Chat for exploration: Test ideas in chat before applying to code
  3. Commit before big edits: Especially before using Copilot Edits
  4. Keep undo close: Train your muscle memory for Cmd+Z

Summary

For quick undos, use Ctrl+Z. For file recovery, use VS Code’s Local History. For safety, commit before big Copilot sessions.

If you want protection without thinking about it, automatic snapshot tools capture every change so you can always recover.


mrq captures every file change automatically while you code with AI. One command to start, instant recovery when things break.

Written by mrq team