Skip to main content

VSCode Local History Save My As*

Visual Studio Code (VSCode) is not only a powerful coding editor but also provides a safety net for those moments when files disappear unexpectedly

––– views

Today, I performed a series of operations that unfortunately led to the loss of files in my workspace. However, thanks to the help of my friends, I discovered a neat trick to recover the files.

The Misstep

In my workspace, without having executed git add, I went ahead with the following commands in the terminal:

To my dismay, my files vanished after this sequence of commands. It's crucial to note that git stash will not save unadded files, and after git clean -fd those files were purged, leaving no trace in the git history.

The Recovery

Thankfully, VSCode has a feature known as 'Local History,' which maintains a record of past file states. Here's the step-by-step guide I followed to restore my lost files:

  1. Press Cmd + P.
  2. Type 'Local History: Find Entry to Restore'.
  3. Enter the path of the lost file you're looking for.
  4. Take a screenshot.
  5. Manually restore the file, and remember to do it promptly.

I can't stress enough the importance of acting swiftly as the local history is periodically pruned. This minor adventure reminded me of the importance of frequent commits and backups. However, knowing that VSCode has features such as 'Local History' provides an extra layer of reassurance for those unforeseen moments of panic.

Stay safe and commit often!