Last weekend I had a strange situation. It all started when I noticed on GitLab that one of my folders in the repository was actually a submodule. It was already late, so I went on Stack Overflow to find a thread about detaching a module from a repository :)
Restoring git rm files with VSCode
After successfully copying a few commands, I looked at what I've done and thought, oh my god - I deleted the entire folder without committing any changes. What's worse, I found out that when detaching a submodule forcefully, Git uses the rm -rf command. So what now? Well, I tried looking for options in Git, but it dawned on me that no reset would help because these files simply didn't exist in my repo, they were just a submodule with locally uncommitted changes. I could go on about all the methods I tried, but let's cut to the chase - VS Code Local History saved me.
VS Code Local History
Ok, so it turns out basically every file you ever edit, has its own local timeline saved in VSCode which tracks file saved events. Restoring a file is really simple, all you need to do is:
- Click Ctrl/CMD + Shift + P
- Select
Local History: Find Entry To Restore
- Filter results by something like folder name
- Open file
- Click Tick Icon to Restore It
Going file by file that's exactly how I managed to restore all of my deleted content!
P.S I didn't make this article too long because if you're in a similar situation you're probably looking for a solution asap and googling 'recover git rm files' or going through stack overflow. So no worries - VS Code has got you covered.