178

Using Visual Studio Code Version 1.8.1 how do I restore a deleted file in the recycle bin?

Yu-s-uF
  • 85
  • 1
  • 8
user2584621
  • 2,305
  • 2
  • 15
  • 9
  • 7
    Since VS Code shows that hint inside the program I find this question very legit. I too looked for a minute inside of the program before googling (and landing here) and before looking in the system trash bin ;) – Manuel Manhart Dec 29 '16 at 15:44
  • yes, this is a lacking feature – ACV Oct 08 '20 at 19:22
  • I recommend checking out [this underrated answer](https://superuser.com/a/1723403). – Janosh Aug 04 '22 at 23:45
  • 3
    In addition to the recycle bin, check the own vscode backsup: `Local History: Find Entry to Restore` – tokland Jan 31 '23 at 09:47
  • The previous comment is by far the easiest solution. It looks to have been added [somewhat recently](https://github.com/microsoft/vscode/issues/145461). – Andrew Feb 09 '23 at 20:30

27 Answers27

249

It uses the normal trash bin of your system. So you can grab it our of there.

In Windows you find it in the explorer, in Linux it is as well in Konquerer / Nemo / ...

Manuel Manhart
  • 4,819
  • 3
  • 24
  • 28
  • 4
    In Linux, you can restore using a terminal with the `trash-cli` package. `trash-list` will list all files in the trash, `trash-restore foo` let you guide you through restoring a file named foo. Useful in ChromeOS where there may be no GUI app with access to the Linux trash installed. – Ray Foss Nov 09 '20 at 20:30
  • 3
    I arrived here because I accidentally rm'd an important file, trash-cli did the trick. You just litteraly saved me @Ray – SamuelRousseaux Dec 23 '20 at 10:46
  • For me the debugger wreaked havoc and deleted the folder. Nothing in the Recicle Bin. The tabs disapeared too. – Spartan Jun 21 '22 at 19:53
  • 6
    Found it in one of `%APPDATA%\Code\User\History` subfolders though. – Spartan Jun 21 '22 at 20:45
  • 1
    @Spartan You just saved me a bunch of time. I accidentally deleted my whole src folder instead of one of the subfolders and was able to recover the files that weren't in version control yet. – WillB3 Jul 06 '22 at 21:29
  • 2
    @Spartan You saved me days recoding it thanks a lot. This must be the most memorizable life saving I get from Stackoverflow – Ho Quang Lam May 12 '23 at 04:57
  • But be aware that only saved files occur in the History folder, deleted + unsaved files don't. – Manuel Manhart Jun 12 '23 at 11:07
60
  1. First go to Recycle Bin of your local machine.
  2. Your VS code deleted files is there in Recycle Bin.
  3. So, Right click on deleted files and select-> Restore option then your deleted files will be automatically restored in your VS code.
Ravi Mengar
  • 1,181
  • 1
  • 11
  • 18
43

If you just deleted the file, know that VSCode 1.52 (Dec. 2020) will support:

Undo file operations in Explorer

Explorer now supports Undo and Redo for all file operations: delete, rename, copy, move, new file and new folder.

Make sure the focus is in the Explorer and trigger the Undo or Redo commands and your last file operation will be undone or redone respectively.
Keep in mind that we have separate undo stacks for the editor and the explorer and we choose which one to undo based on focus.

Explorer Undo -- https://media.githubusercontent.com/media/microsoft/vscode-docs/vnext/release-notes/images/1_52/explorer-undo.gif

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    This is especially relevant, as there's currently a bug in VSCode (or, more accurately, I think it's in Electron or some dependency) that causes VSCode to freeze when you trash a file, so some users have bypassed the "trash" file, and just straight up delete them. – Andrew Aug 04 '21 at 21:20
  • Is there a way to disable that feature? Because now we can break the project because of an 'Undo' command executed incorrectly. Something can be undone inside the explorer panel and it can be confusing to understand what happened and why the project is broken, again, and again. We type cmd+z many times a day, you changed this feature that might lead us to undo something elsewhere we're not really looking at. – rochasdv Aug 16 '21 at 23:30
  • @rochasdv I don't see an undo setting related to this feature. So that would be a good request to record as an issue. – VonC Aug 17 '21 at 07:29
  • 1
    This was a lifesaver, accidentally deleted a file I'd just spent 20 minutes revising and hadn't committed yet and it didn't show up in the trash, but undo worked! – Soren Bjornstad Jun 24 '22 at 01:52
  • 2
    this. comment. has. saved. my. life. I. don't. know. how. to. thank. you. – Allexj Sep 25 '22 at 23:44
  • 1
    saved my life! cmd+Z was not working but using the drop down worked! – Sadra Apr 07 '23 at 21:11
29

Click in empty space of VS Code's explorer (it's where you see files listed vertically) and press undo Ctrl + z

It'll recover your permanently deleted files too.

VS Code is a lifesaver. ✌

lockhrt
  • 597
  • 6
  • 11
  • 1
    This. This VERY HINT saved my life (or my recent changes, or whatever). *In an empty space, where you see files listed vertically*. PHEW, thank you!! – Francisco A. Cerda Jun 11 '22 at 21:52
  • 1
    THIS SOLUTION SAVED A TWO-DAYS-WORK AND MY SANITY – Anwarvic Feb 03 '23 at 19:01
  • Don't know what empty space you mean... I've tried to click every single fragment, but it does not help. Nothing is happening... Damn.... – Alexander Feb 24 '23 at 21:37
  • @Alexander Click inside the file explorer of the VS code. It usually sits on the left side and you see files listed vertically. And then press undo. If you have restarted VS code in the meanwhile then it might not be possible anymore. – lockhrt Feb 28 '23 at 06:57
  • @lockhrt it did not help. Probably it works for a separate file. In my case - I've deleted a whole folder... – Alexander Feb 28 '23 at 11:27
  • 1
    oh this worked for AWS instance.. even it was permanently deleted. – Nawin K Sharma Jun 16 '23 at 19:54
18

Running on Ubuntu 18.04, with VS code 1.51.0

My deleted files from VS Code are located at:

~/.local/share/Trash/files

Every deleted file have a corresponding .trashinfo file which contains details about where the file is deleted from and deletion date and these are located at:

~/.local/share/Trash/info

More info here.

To search for your deleted files:

find ~/.local/share/Trash/files -name your_file_name 

In case you deleted files form a mounted ntfs filesystem, they will be located at:

/path_to_mounted_fs/.Trash-$UID

You can get $UID by doing echo $UID in your terminal.

Hope my case helped!

Shivanshu
  • 129
  • 2
  • 8
Yuanjing Cai
  • 181
  • 1
  • 3
15

I know the OP says Recycle Bin. What I do though is recreate the file, especially if it's a single file. And when in the file, I just press CMD+Z (I'm on a Mac) and I get my file back.

  1. Recreate the file in the same directory from where it was deleted.
  2. CMD+Z inside of the newly created file.
flash
  • 1,663
  • 16
  • 16
  • 1
    This did not work for me but made it worse ... – mahatmanich Dec 01 '22 at 08:20
  • You can also see the changes in the Timeline section. You can create a new file with the same file name, and the VS Code Timeline will show the content from before it was deleted. – Moshe G Aug 29 '23 at 03:19
13

If you can't find your files in the Windows Recycle Bin as it happended to me
(debugger went rogue and deleted the project folder)
look in the %APPDATA%\Code\User\History\ subfolders sorted by date modified. There I could retrieve my seemingly lost files.

Spartan
  • 664
  • 9
  • 12
  • 7
    And if you're using remove development, `~/.vscode-server/data/User/History` --> grep through the files there – iutlu Jun 28 '22 at 08:38
  • @iutlu Your comment worked for me. You are a life saver. Please considering posting your comment so many other people can benefit from it. – Akintomiwa Opemipo Jul 23 '22 at 01:32
  • 1
    Spent ages trying to look it undelete options for WSL/ubuntu and few looked promising. However Spartan/iutlu is exactly what I needed. Life saved. – MattH Jul 26 '22 at 12:51
10

I accidentally discarded changes in the Source Control in VS Code, I just needed to reopen this file and press Ctrl-Z few times, glad that VS Code saves your changes like that.

Eugene Ihnatsyeu
  • 1,299
  • 13
  • 15
9

who still facing the problem on linux and didnt find it on trash try this solution

https://github.com/Microsoft/vscode/issues/32078#issuecomment-434393058

find / -name "delete_file_name"
Muhammad
  • 601
  • 2
  • 9
  • 18
6

If you have permanently deleted files, on macOS, you can see the history (the last month I guess) in $HOME/Library/Application Support/Code/User/History/. You will have to find your file(s) by looking at each entries.json file in every subfolder and rename the last version of your file.

There is probably a similar way on windows and linux but I don't know the precise paths.

MajorTom
  • 327
  • 2
  • 5
  • 1
    Thanks a lot for this @MajorTom, in my case I lost the files from VSCode. In **entries.json** there's a reference to the original file, where every log is a snapshot with a timestamp. These _tsx_ files contains the file state at given time. `code "entries" :[ { "id": "S17j.tsx", "timestamp": 1663258186343 }, { "id": "A8Ql.tsx", "timestamp": 1663329533427 }, ] ` – Fer Alvarez Sep 16 '22 at 16:56
4

I tried most of the options above but none worked.

What worked for me was clicking and highlighting the folder where the file was deleted from in vscode. Then while it is selected, hit CTRL + Z. This works on windows.

Hitting CTRL+Z without highlighting that folder didn't work.

Henry Obiaraije
  • 301
  • 3
  • 10
3

Just look up the files you deleted, inside Recycle Bin. Right click on it and do restore as you do normally with other deleted files. It is similar as you do normally because VS code also uses normal trash of your system.

John
  • 972
  • 1
  • 7
  • 24
2

While pushing a repository to Github through Vs Studio code I deleted whole folder and they were not available in Recycle bin also. Here is how I recovered those files. For Windows.

The method is to restore the previous version of the Drive in which the deleted file existed

I had deleted files from G: drive, the below images are self explanatory

Open properties menu of the drive

enter image description here

In properties go to previous versions tab, where you can find the previously stored versions of that drive along with date at time of backup use open or click on restore to get the previous version of that drive.

enter image description here

Note: Manipulations in the drive after restore point won't be available

2

I am not sure how I deleted a file in VS Code, and couldn't find it in recycle bin. Found the file using the History feature of File Explorer.

File Explorer Options

File Explorer File History

File History is on

gurkan
  • 884
  • 4
  • 16
  • 25
  • Good tip, i found that vscode has its own history folder at `%APPDATA%\Code\User\History` should the feature be disabled... – Spartan Jun 21 '22 at 20:40
2

A month recovery can be done in visual studio code 1 Right click on file and 2 click Open Timeline and 3 select file from timeline 4 the last time file saved by you 5 and your last change of the file is recovered

NOTE : Not only last but all the previously saved check points can be recoverd from vs code

1

I am working on Windows with a Ubuntu WSL. I permanently deleted a file by mistake and was not able to restore it from the recycle bin nor by doing anything else.

I however, was able to get my files content by going to "Timeline" and see all my previous modification (it will open a comparison window).

Hope it will help somebody.

1

For Mac, try to search some parts of the code in the deleted file in the following path:

~/Library/Application Support/Code

I found a deleted file in this folder

~/Library/Application Support/Code/Backups
mallet
  • 2,454
  • 3
  • 37
  • 64
1

I had the case that I, accidentally, deleted a committed file (git) with a ton of additional uncommitted changes, and I could not get it back. (two days of work! yeah, I know, commit early commit often, I know ...)

I had no linux trash can setup on my docker instance and was developing via remote ssh.

I tried to recreate the file and then do a ctrl+Z to recapture the changes as some suggested here. This did not work for me.

So after a struggle over an hour I finally gave up and thought the changes to the file were lost.

However,

  1. I discarded the changes in git, that the file was deleted.
  2. And THEN I retried ctrl+Z and boom all the changes previously came back magically!

I was a happy camper!

mahatmanich
  • 10,791
  • 5
  • 63
  • 82
1

This worked for me!

  1. Try to recreate files (with extensions - files should be empty) and directory structure.
  2. There should be a TIMELINE on the left side of the bottom VSC EXPLORER view (default setting).
    VSC timeline view
  3. Right click on the last File Saved, then choose Restore Contents. VSC timeline view - with opened context menu

Hope it saves someone like it saved me 3 hours of life!

If not, I recommend trying the way described in this answer (by @iutlu [remote development] and @Spartan) - it was helpful to me, only that there were a lot of versions of each file - but I'm not saying no: the files were!

rakso
  • 35
  • 1
  • 5
  • 1
    This should get more upvotes! Just discovered the same thing myself and posted the same answer only to stumble upon this one! – nikhilweee Aug 11 '23 at 05:40
0

Yes, I know this question is about VS Code but I think I can help someone. I permanently deleted a file, and I tried all the tips wrote here with no success. So I had to recover the file from OS Linux following this

grep -a -C 500 -F 'Unique string in text file' /dev/sda
Rodney Salcedo
  • 1,228
  • 19
  • 23
0

It was asked above if there is a way to disable the ability to delete a file you created with an undo (@rochasdv).

There is a new setting to disable undo for file operations:

Explorer: Enable Undo default is warn, confirmation dialog

You can also set it to disable so that your files/folders will not participate in undo operations.

You can alo set it to allow - the pre-new setting situation.

Currently, this new setting is in the Insiders Build v1.64 so it may be in Stable early February, 2022.

Mark
  • 143,421
  • 24
  • 428
  • 436
0

If you want to find the deleted files, after running

Run

in order, you can see the changes you have made before using

APPDATA%\Code\User\History\

path. By the way, you have the opportunity to examine the files according to the recording dates.

0

VS Code saves any file you actually edit - not all files in a project directory however - to a local directory :

Linux : $HOME/.config/Code/User/History
Mac : ~/Library/Application Support/Code/History
Windows : %APPDATA%\Code\User\History\

There are directories created for every file you edit with different versions tied to a timestamp/session defined in a JSON file called entries.json like @MajorTom mentioned so your work is saved but it is a tad bit cumbersome to restore a directory like you would restoring from the trash.

If you simply want to restore the latest version of a directory you accidentally deleted, you can run this .net console utility and it will restore everything it possibly can to a directory you specify in the appsettings.json.

https://github.com/karlpothast/VSCodeRecoveryTool

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34505223) – user12256545 Jun 10 '23 at 13:09
  • 1
    Edited and added context - thanks – karlpothast Jun 12 '23 at 09:12
0

If the deleted folder from vscode on a macbook is present in One Drive (Which is a common thing for software professionals) the deleted folder will not be in Recycle bin and rather in One Drive home folder.

Balki
  • 1
  • 1
0

EASY FIX

If you know the name of the deleted file then recreate it with the exact name and filepath. Open the file, then go to TIMELINE as shown in the image below, you'll find all the changes you made to the file.

IMAGE

Gurukota
  • 1
  • 1
-1

If your local directory has git initialized and you have not committed the changes that include the delete, you can use git checkout -f to throw away local changes.

coltdorsey
  • 93
  • 5
-2

If you completely delete any of the components in angular using visual code, you can restore it Go to Recycle Bin and restore the deleted component that will be restored in the project.

NITHESH
  • 7
  • 2