DEV Community

How I restored my deleted file in VSCode: A cool trick you should know ๐Ÿ”ฎ

Krzysztof Platis on July 12, 2024

Hey there! Let me share a crazy experience I had recently. I was working on a lengthy piece of code in a new file in VSCode. After spending hours p...
Collapse
 
e1bos profile image
Luca

I created an account just to thank you.

I had an assignment with a controller file with over 500 lines of code, and I was helping my professor debug a PHP setup error and forgot to rename the dummy file. All my code was gone, I was devastated, went through total shock.

You saved my assignment, my time, and my mental health. Thank you for writing this, for sharing this. I wish the utter best for you.

Collapse
 
krisplatis profile image
Krzysztof Platis

I'm happy it worked for you! ๐Ÿ™Œ

Collapse
 
laurent_ionesco_a77425eac profile image
Laurent Ionesco

It also works if you worked on a remote server. You opened files through Winscp, you edited them in VS Code (it opened and saved them in a temp directory). If something nasty happened on the server and you overwrote a file, you can recover it with the method here. Thanks Krzysztof!

Collapse
 
krisplatis profile image
Krzysztof Platis

Wow. Awesome you're sharing it! Thanks for info!

Collapse
 
marxism06 profile image
Marx Miguel Escaรฑo

It's May 6, 2025, 12:30 AM. I got lost in the commands in Git Bash and accidentally removed my files. I couldn't even see them after relogging. I panicked and cried a little โ€” I worked on this the whole day just for it to disappear. But I searched for a solution, and it worked! I have a project presentation at 2 PM, haha. Thanks you sir!

Collapse
 
mo_rizwan_amu profile image
Mo Rizwan

i was very panic because mistakenly some important file overwritten in vs code. so that i had lost all important code from vs code file then after i searched many platform but did not find solution. then after long time i found write solution to retrieve our overwrite file/code. Now i have restored code so i fell very happy. thank you. live long

Collapse
 
krisplatis profile image
Krzysztof Platis

Happy to hear it helped! I can feel for you.
PS. If only you want, feel free to buy me a coffee ๐Ÿ˜‰ buymeacoffee.com/krisplatis

Collapse
 
noel_benitezcruz_dfe5d5e profile image
Noel Benitez Cruz

Ive almost pooped a brick when .git ate up 6 months of hard work by replacing master with an ancient repo... I screamed , i cussed, broke stuff and had a hissy fit just to vent, but ai suggested that there were file caches for visual studio, one Google search later and im here... MANY MANY MANY MANY THANKS :3 ... also thanks Microsoft for Visual Studio, have I coded with nano the "1337" way I woudlnt have backups

Collapse
 
senthilkumaranc profile image
SenthilKumaranC • Edited

I have lost of all my files. It got Permanently deleted. Unable to recover from anywhere.

Finally able to recover all files because of this post.

Thanks to you and also to my brother Arvind who pointed out this post.

Thanks to VS code team too.

Collapse
 
dotnet_codemaster profile image
Richard May

Thanks Krzysztof! Your post was a life saver!

I was moving a file from one directory/folder to another within the Solution Explorer view of VS Code, and my file completely disappeared without a trace. No history of it via MS Windows functions or commands (e.g. FileExplorer, Command prompt). It had just vanished! I'm not sure if this is a known bug in VS Code or not, or if anyone else had run across this issue!

Anyway, the file had not been committed to my github repository, yet, and I was very panicked to say the least. So I thought I would do a quick "Google" search, which I am glad I did, as it brought up your post!

After following your instructions, my file was restored!
Thank you! Thank you! Thank you!

Collapse
 
_3856c3b004b1c59e0f profile image
ฮฃฯ€ฯ…ฯฮฟฯ‚

Brother you saved my life I had weeks of work lost and thanks to this i recovered it, I couldnt believe it at first. I sincerely wish God always be with you and that everything in life will go the way you want it to.

Collapse
 
alex_ilchenko_ef9a7b53408 profile image
Alex Ilchenko

I created an account just to thank you!

I'd been working on a project for about a week when I broke it with the wrong Git command. All my changes reset to the last commit. I panicked, almost died, couldn't sleep all night, and felt a pain in my body like a breakup. At 5 AM, I realized there must be some history beyond Git's.

Thanks a lot!

And thanks to the VS Code developers for including that feature. By the way, it could be improved, as well as git history as it can accidentally reset unstaged changes.
Nice to see comments from people who've rescued their life's work.

Collapse
 
j_l_dd6c8bd437cad5fbe9312 profile image
J L

Saw someone said you can just open the recycle bin and restore.
However, if your pc decided to crash during a file save on a hard drive failure, causing an empty file on reboot.
This has to be the only solution. Thank you.

Collapse
 
marxism06 profile image
Marx Miguel Escaรฑo

It's May 6, 2025, 12:30 AM. I got lost in the commands in Git Bash and accidentally removed my files. I couldn't even see them after relogging. I panicked and cried a little
I worked on this the whole day just for it to disappear. But I searched for a solution, and it worked! I have a project presentation at 2 PM, haha. Thanks you sir!

Collapse
 
hashim_hussain_5 profile image
Hashim Hussain

Amazing it works perfectly thanks for info.

Collapse
 
rahulkad profile image
Rahul Kadam

You just saved my life. Thanks

Collapse
 
alexantoshuk profile image
alexantoshuk

I accidentally did a git checkout but forgot to commit, all the files were replaced by the old version. Local History helped me restore everything! Thank you!

Collapse
 
ayyash profile image
Ayyash

you could have just opened the trash bin and restored :) but yes this is easier

Collapse
 
krisplatis profile image
Krzysztof Platis

Good idea. I've tried it too, but the file wasn't in the trash. Likely, because I've accidentally removed it with some git command (but not regular "delete file" action in the system).

Collapse
 
abhishek_waghmare profile image
Abhishek Waghmare

Thank you, you just saved my 2 weeks of work!

Collapse
 
pereafrantz profile image
Frantz Perea Cobos

I just can say... you saved me a day of work.

Collapse
 
wuyen profile image
Wuyen

Thank you , you saved my life

Collapse
 
sayidina_ahmadalqososyi_ profile image
Sayidina Ahmadal Qososyi

thanks :")

Collapse
 
amtul__sadiya_ec9c2c3e707 profile image
amtul_ sadiya • Edited

I just wanted to say a huge thank you for your post. I messed up my project and thought I lost everything, but your solution saved me! I canโ€™t tell you how relieved I am.
thanks Krzysztof! ๐Ÿ™Œ๐Ÿ™Œ

Collapse
 
krisplatis profile image
Krzysztof Platis

Thanks for sharing your feelings! I can totally feel for you and could feel the same... twice ๐Ÿ˜… - it happened to me once again a few months later after sharing this blogpost that I deleted my files once again ๐Ÿ™ˆ)
By the way, just in case you'd like share your joy in other ways too, you might want to buy me a coffee: buymeacoffee.com/krisplatis ๐Ÿ˜‰

Collapse
 
nishikanta_sahoo_9be247db profile image
Nishikanta sahoo

thanks bro

Collapse
 
shtefcs profile image
Stefan Smiljkovic

This is amazing, just had a guy on Discord shared this to me

Thank you both!

 .

Collapse
 
dev_named_will profile image
Will

Thank you for the save ๐Ÿ™

Collapse
 
abdul_azeez_77598ac9a119d profile image
abdul azeez

You save my day โ™ฅ

Collapse
 
user7932 profile image
Maximus

WOW THANK YOU!

Your post helped me rescue a co-worker from a serious jam.
Even now, it's unclear how the original files were lost, but the vscode cache was able to bring them back.

Collapse
 
mekdim_tam profile image
Mekdim Tam

thanks bro you saved me

Collapse
 
krisplatis profile image
Krzysztof Platis

Happy to hear it helped! ๐Ÿ™Œ
Feel free to buy me a coffee if you want ๐Ÿ˜‰ buymeacoffee.com/krisplatis

Collapse
 
rak_acoustic_48e4b738c334 profile image
RAK ACOUSTIC

*Your article saves my day too *

Collapse
 
taras_lozovoy_496b239c4f2 profile image
Taras Lozovoy

Thanks a lot, it really helpful

Collapse
 
emma_miller_ca3f736a2b808 profile image
Emma Miller

thanks.

Collapse
 
gustavo_enriquez_dc6cb83f profile image
Gustavo Enriquez

wow!! work thank u so much !! me too, I created an account just to thank you

Collapse
 
krisplatis profile image
Krzysztof Platis

I'm so happy it helped you! ๐Ÿ™Œ

Collapse
 
akintomiwafisayo profile image
akintomiwa-fisayo

You're a superhero, you just saved me from depression ๐Ÿค— .

Collapse
 
barry_valizade_4257cf449c profile image
Barry valizade

Thank you, you save my time <3 :)

Collapse
 
byiringiriro_fabrice_a891 profile image
BYIRINGIRIRO Fabrice

hhhh life saver I was about to go crazy

Collapse
 
kadario profile image
Alexander • Edited

You are my hero! Thanks for the artical! It was really helpful!
I asked AI to rename some of my files with code, so he created new files and removed old, but didn't apply my latest changes, I was added during the day. Asked to restore but no luck.
So the VS code file history help me a lot!

Collapse
 
ggonzalez5flow profile image
ggonzalez5flow

I created an account you to say:

THANK YOU! I had been working on a script like for 5 hours!

Collapse
 
krisplatis profile image
Krzysztof Platis

Happy to hear you saved your hard work! ๐Ÿ™Œ