How to recover files deleted with git rm or how to recover uncommitted submodule with vscode

By Artur Czemiel

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:

  1. Click Ctrl/CMD + Shift + P
  2. Select Local History: Find Entry To Restore
  3. Filter results by something like folder name
  4. Open file
  5. 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.

author

Artur Czemiel

CEO

I can help you create graph sourced source of the truth-based architecture of the existing app or plan a new one.

Could use some help with Tech?

author

Artur Czemiel

CEO

I can help you create graph sourced source of the truth-based architecture of the existing app or plan a new one.

Could use some help with Tech?

Next Article

Aexol shines at Europe's biggest hackathon - HackYeah 2023!

Read article
Next Article

Aexol shines at Europe's biggest hackathon - HackYeah 2023!

Read article
Share
Fast Landing Pages
Plugins
Let's start working together!
What we can do
Let's start working together!