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 in Visual Studio Code 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 discarded files in Visual Studio Code
How to recover discarded files in Visual Studio Code

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 discarded files in Visual Studio Code
How to recover discarded files in Visual Studio Code

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.

Leave a Reply

Your email address will not be published.