How I restored my deleted file in VSCode: A cool trick you should know 🔮
Krzysztof Platis

Krzysztof Platis @krisplatis

About: Welcome to my blog. I'm Javascript Enthusiast • Fascinated with internals of Vue, React and Angular • Focused on the business needs of Clients • Architect @ SAP Spartacus core team. Opinions R my own

Joined:
Nov 22, 2019

How I restored my deleted file in VSCode: A cool trick you should know 🔮

Publish Date: Jul 12 '24
219 40

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 perfecting it, I accidentally deleted the file before committing it to Git. I only realized the mistake the next day. Total nightmare, right?

The Panic Moment

At first, I was in complete shock. I just stared at my screen, thinking, "Did that really just happen?". My heart started racing, and I felt this wave of panic wash over me. All that hard work, gone. Nothing in the Trash Bin. But then, I started googling whether it was possible to restore a deleted file from VSCode, and I found, to my surprise, a Stack Overflow question where someone in the comments suggested the following cool trick.

The lifesaver: Local History in VSCode

So, there's this feature in VSCode called "Local History: Find Entry to Restore." It basically keeps a history of your files locally, which means you can go back and restore previous versions even if you've deleted them! How cool is that!

How I got my file back

  1. Open command palette

    • First, I opened the Command Palette by pressing Cmd+Shift+P
  2. Find the local history command

    • Then, I pasted the phrase "Local History: Find Entry to Restore" in the Command Palette. It popped up in the list, so I pressed Enter. Image description
  3. Search for my deleted file

    • Next, it asked me to type the name of the file I deleted. I did, and to my happy surprise, my deleted file was there!
  4. Choose the right version

    • After pressing Enter, I was presented with a list of snapshots of my file that VSCode remembered for me. I picked the most recent version and pressed Enter again. Image description
  5. Restore the file

    • Finally, just like that, VSCode restored the contents of my file! It was like magic! I was so happy. Then it sufficed to just save this file contents on my disk with the hotkey Cmd+S and I could commit it now with Git. 🎉

The Happy Ending

Seeing my code back on the screen was such a relief. I avoided a counter-productive big loss of my work. Not only did I get my work back, but I also learned a super useful trick that I'm now excited to share with you. I hope you'll never need to use it, but... it's better to be prepared 😉

Feel free to buy me a coffee 😉 ☕️👇 Thank you! 🤗

Buy Me A Coffee

Comments 40 total

  • Rahul Kadam
    Rahul KadamJul 24, 2024

    You just saved my life. Thanks

  • Ayyash
    AyyashJul 28, 2024

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

    • Krzysztof Platis
      Krzysztof PlatisJul 29, 2024

      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).

  • Will
    WillAug 5, 2024

    Thank you for the save 🙏

  • akintomiwa-fisayo
    akintomiwa-fisayoAug 10, 2024

    You're a superhero, you just saved me from depression 🤗 .

  • Barry valizade
    Barry valizadeAug 21, 2024

    Thank you, you save my time <3 :)

  • abdul azeez
    abdul azeezAug 24, 2024

    You save my day ♥

  • Emma Miller
    Emma MillerAug 27, 2024

    thanks.

  • Frantz Perea Cobos
    Frantz Perea CobosSep 3, 2024

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

  • Laurent Ionesco
    Laurent IonescoSep 8, 2024

    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!

  • BYIRINGIRIRO Fabrice
    BYIRINGIRIRO FabriceSep 16, 2024

    hhhh life saver I was about to go crazy

  • Wuyen
    WuyenSep 17, 2024

    Thank you , you saved my life

  • Mekdim Tam
    Mekdim TamSep 29, 2024

    thanks bro you saved me

  • Abhishek Waghmare
    Abhishek WaghmareOct 5, 2024

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

  • SenthilKumaranC
    SenthilKumaranCOct 17, 2024

    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.

  • Hashim Hussain
    Hashim HussainNov 24, 2024

    Amazing it works perfectly thanks for info.

  • Luca
    LucaNov 26, 2024

    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.

  • Sayidina Ahmadal Qososyi
    Sayidina Ahmadal QososyiNov 28, 2024

    thanks :")

  • RAK ACOUSTIC
    RAK ACOUSTICDec 9, 2024

    *Your article saves my day too *

  • alexantoshuk
    alexantoshukDec 14, 2024

    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!

  • amtul_ sadiya
    amtul_ sadiyaFeb 7, 2025

    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! 🙌🙌

    • Krzysztof Platis
      Krzysztof PlatisFeb 10, 2025

      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 😉

  • Mo Rizwan
    Mo RizwanFeb 24, 2025

    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

  • ggonzalez5flow
    ggonzalez5flowMar 14, 2025

    I created an account you to say:

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

  • Krzysztof Platis
    Krzysztof PlatisMar 26, 2025

    Happy to hear it helped! 🙌
    Feel free to buy me a coffee if you want 😉 buymeacoffee.com/krisplatis

  • Richard May
    Richard MayApr 19, 2025

    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!

  • Noel Benitez Cruz
    Noel Benitez CruzApr 25, 2025

    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

  • Nishikanta sahoo
    Nishikanta sahooMay 3, 2025

    thanks bro

  • Marx Miguel Escaño
    Marx Miguel EscañoMay 5, 2025

    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!

  • Marx Miguel Escaño
    Marx Miguel EscañoMay 5, 2025

    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!

  • Taras Lozovoy
    Taras LozovoyMay 6, 2025

    Thanks a lot, it really helpful

  • Σπυρος
    ΣπυροςMay 17, 2025

    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.

  • Gustavo Enriquez
    Gustavo EnriquezJun 3, 2025

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

  • Maximus
    MaximusJun 27, 2025

    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.

Add comment