Today, I performed a series of operations that unfortunately led to the loss of files in my workspace. However, thanks to the help of my friends, I discovered a neat trick to recover the files.
The Misstep
In my workspace, without having executed git add, I went ahead with the following commands in the terminal:
To my dismay, my files vanished after this sequence of commands. It's crucial to note that git stash will not save unadded files, and after git clean -fd those files were purged, leaving no trace in the git history.
The Recovery
Thankfully, VSCode has a feature known as 'Local History,' which maintains a record of past file states. Here's the step-by-step guide I followed to restore my lost files:
- Press Cmd + P.
- Type 'Local History: Find Entry to Restore'.
- Enter the path of the lost file you're looking for.
- Take a screenshot.
- Manually restore the file, and remember to do it promptly.
I can't stress enough the importance of acting swiftly as the local history is periodically pruned. This minor adventure reminded me of the importance of frequent commits and backups. However, knowing that VSCode has features such as 'Local History' provides an extra layer of reassurance for those unforeseen moments of panic.
Stay safe and commit often!