How to recover discarded files in Visual Studio Code

How to recover discarded changes in Visual Studio Code

A while ago in my first weekly update I already told you about the files I deleted by pressing the Discard All Changes in stead of the Stage All Changes button in Visual Studio Code. Yes, the GUI button…

How to recover discarded changes in Visual Studio Code
How to recover discarded changes in Visual Studio Code

It felt like my heart was being ripped out of my body. All the changes from the past few days were overwritten by older versions and even new files were remove from the stage.

And now you have the same problem… You probably looked for a way to recover these files from Visual Studio Code and came across an Extension.
I’m happy to tell you that Visual Studio Code has this option baked in as well.


Let’s recover files from the local history

Open Visual Studio Code and press CTRL + SHIFT + P simultaneously. This will open the Command Palette.

Type in Local History and select Local History: Find Entry to Restore.

How to recover discarded files in Visual Studio Code

A screen will open where you can see your recent (deleted) files.
You can scroll through the list and find the correct file.

How to recover files in Visual Studio Code from the local history
How to recover files in Visual Studio Code from the local history

After you select a file, you will be asked which version you want to open.
Select the correct version here.

How to recover discarded files in Visual Studio Code

After opening the version, a screen will open where the version will be compared with the version in your Workspace, or the file will be opened and displayed in its entirety.

How to recover files in Visual Studio Code from the local history
How to recover files in Visual Studio Code from the local history

And it is that easy! Success with it.


Disclaimer

Unfortunately I can’t find anything about this on the Visual Studio Code website. Also when searching for the commands nothing comes up.

This may only work because I have Git installed.
Unfortunately I can’t test it without Git, so I can’t say 100% that this always works.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell DevOps Engineer. In my spare time I write about interesting stuff that I encounter during my work.

3 thoughts on “How to recover discarded files in Visual Studio Code”

  1. Hi. Is there any other way to recover the files? I can’t see anything in my local history. Maybe because I restarted VS code. I have 10.000 untracked files (my whole laptop) in my source control in VS code. I think I messed up somehow initializing my Mac user account folder as a local Git repo. Then messed up further by selecting “discard all changes” of uncommitted untracked files and lost everything on my Mac. I was just trying to clean up resource control panel as it made vscode very slow. A lot of these file I don’t have a backup anywhere (Time Machine or ICloud or hard drive). Do you have an idea how to fix this? Much appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *