Recover Deleted Files and Unwanted AI Changes with Local History in VS Code/Cursor
The most important tool in your toolbelt is the one that saves you when things go wrong. Whether you accidentally delete a critical file or an AI agent overwrites hours of your work, the fear of losing progress is real. Even before you've had a chance to commit to Git, disaster can strike.
This is where VS Code's and Cursor's built-in Local History feature becomes your ultimate safety net. It automatically keeps a record of your file changes, allowing you to restore deleted files or revert to previous versions with ease, completely independent of your source control.
Workflow demonstrated in this lesson:
- Demonstrates recovering a file that was accidentally deleted from the terminal.
- Shows how to revert unwanted changes made by an AI coding assistant.
- Uses the Command Palette (Cmd/Ctrl + Shift + P) to access "Local History: Find Entry to Restore".
- Navigates through a timeline of file saves to find the correct version.
- Restores the file's contents or the entire file with a single command.
- Compares the current version with a historical version using a diff view.
Key benefits:
- Instant Recovery: Restore accidentally deleted files in seconds.
- Undo AI Mistakes: Easily revert changes made by AI agents that didn't work out.
- Git-Independent: Provides a safety net even when you're not using Git or haven't committed your changes.
- Granular History: See a detailed timeline of changes for any file you've worked on.
Summary
This lesson demonstrates the power of the built-in Local History feature in VS Code and Cursor, an essential safety net for any developer. It shows how to recover an accidentally deleted file and revert unwanted changes made by an AI agent, all without relying on Git. By using the Command Palette to find and restore entries from the local history, you can easily navigate a timeline of your file's past states, compare differences, and restore your work, ensuring that a simple mistake or a faulty AI suggestion doesn't lead to lost progress.
Prompts
TS index.ts convert this into a simple http server
Terminal Commands
rm index.ts
Code Snippets
The lesson starts with a simple file that gets deleted and later recovered.
console.log("Hello via Bun!");