Restore deleted files in visual studio code in the code management menu

25.7k Views Asked by At

I am really devastated because I have accidentally deleted 3 of my files in Visual Studio Code. I did it through the Source Code Management menu on the left side. Now my question... Is there any possibility to restore the 3 files I deleted like this? I would appreciate any answer and maybe you want to know: I use Windows :-( I tried to look into the recycle bin of windows but it isn't there. :-(

8

There are 8 best solutions below

0
On

No, you cannot recover those files using VS Code or standard tools. They aren't put in the recycling bin (or your operating system's equivalent), they are removed using git cleanor git reset --hard. Condolences :-(

There are of course utilities for recovering deleted files that may or may not be successful, but that is outside the scope of this question.

0
On

if you accidently click the delete menu option right below rename, as long as you don't panic and like restart your computer or something you can open that directory in the file explorer on your computer

and right click.

there should be options there to undo delete or whatever else you did to the directory.

0
On

VSCode internally keeps the history of any file which has been opened and changed in the editor. In my case, i deleted some files accidentally without adding them ever to git. So to recover such files, We can check in path: C:\Users\<user name>\AppData\Roaming\Code\User\History

This directory contains a lot of individual sub-folder, each of which belongs to a specific file path, which is denoted using the hash as the folder name. For each such subFolder, it has a entries.json file, which keeps track of historical file snapshots. This also contains the path of the original file.

You may manually check this directory to retrieve the latest changes to file. Or, it should be possible to write some small code snippet as well to create directory snapshot by reading all such JSONs. Hope it helps.

0
On

As of 2023

Open VSCode's command menu, and type "Local History" and select "Local History: Find Entry to Restore." Then type the name of the file you deleted.

This has worked for me when "undo" in the file tree has not.

Super easy, and has saved me from despair.

1
On

I accidentally removed a file that wasn't even checked in to git. Google brought me here. The file wasn't in the Trash can either (Ubuntu 18.4 VS Code 1.31.1). Looking at the git output I can see that it used git clean -f to remove it by force).

Fortunately the file was still in the editor. Just press Ctrl+P and type the file name. It should show up in the list of files and if you open it, it says "FILE_NAME (deleted from disk)" on the tab. Just copy/paste the content to where it should be.

2
On

vscode maintains a file-history using its latest TIMELINE view.

How to restore deleted git-untracked files in vscode:

Create the files with the same name at the same directory.

Go to TIMELINE on the File Explorer.

You can get the older versions of the files.

0
On

Answer suggestion Timeline by @Sumanth Lingappa really helped me, but in a slightly different way, in the Timeline go for

  1. "Reveal in File Explorer".
  2. There, in the Parent Folder named as 'History', you will find different folders with each folder having the total history of single file created in the project, open them n restore/copy paste/create all the files .
0
On

Go to file explorer. select folder then from there enter ctl+z. Worked for me