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

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 th…


This content originally appeared on DEV Community and was authored by Krzysztof Platis

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. 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 started 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 eight 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 😉


This content originally appeared on DEV Community and was authored by Krzysztof Platis


Print Share Comment Cite Upload Translate Updates
APA

Krzysztof Platis | Sciencx (2024-07-12T18:06:55+00:00) How I restored my deleted file in VSCode: A cool trick you should know 🔮. Retrieved from https://www.scien.cx/2024/07/12/how-i-restored-my-deleted-file-in-vscode-a-cool-trick-you-should-know-%f0%9f%94%ae/

MLA
" » How I restored my deleted file in VSCode: A cool trick you should know 🔮." Krzysztof Platis | Sciencx - Friday July 12, 2024, https://www.scien.cx/2024/07/12/how-i-restored-my-deleted-file-in-vscode-a-cool-trick-you-should-know-%f0%9f%94%ae/
HARVARD
Krzysztof Platis | Sciencx Friday July 12, 2024 » How I restored my deleted file in VSCode: A cool trick you should know 🔮., viewed ,<https://www.scien.cx/2024/07/12/how-i-restored-my-deleted-file-in-vscode-a-cool-trick-you-should-know-%f0%9f%94%ae/>
VANCOUVER
Krzysztof Platis | Sciencx - » How I restored my deleted file in VSCode: A cool trick you should know 🔮. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/12/how-i-restored-my-deleted-file-in-vscode-a-cool-trick-you-should-know-%f0%9f%94%ae/
CHICAGO
" » How I restored my deleted file in VSCode: A cool trick you should know 🔮." Krzysztof Platis | Sciencx - Accessed . https://www.scien.cx/2024/07/12/how-i-restored-my-deleted-file-in-vscode-a-cool-trick-you-should-know-%f0%9f%94%ae/
IEEE
" » How I restored my deleted file in VSCode: A cool trick you should know 🔮." Krzysztof Platis | Sciencx [Online]. Available: https://www.scien.cx/2024/07/12/how-i-restored-my-deleted-file-in-vscode-a-cool-trick-you-should-know-%f0%9f%94%ae/. [Accessed: ]
rf:citation
» How I restored my deleted file in VSCode: A cool trick you should know 🔮 | Krzysztof Platis | Sciencx | https://www.scien.cx/2024/07/12/how-i-restored-my-deleted-file-in-vscode-a-cool-trick-you-should-know-%f0%9f%94%ae/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.