
Lost Files in Git Without a Commit? Here's How to Recover Them Using VS Code
Written by: Thiago Nunes Batista
Published on 21/01/2025
Last updated: 07/01/2026
Git is the most widely used version control system in the market. As developers, we usually only scratch the surface of what this tool is capable of. In our daily routine, we tend to rely on basic commands such as pull, commit, merge, and push.
However, Git is a powerful and complex tool. Incorrect usage can lead to serious problems, such as losing code that has not yet been committed to the repository. If this has ever happened to you, you probably felt that moment of panic, thinking all the time invested in that code was completely wasted.
If you use VS Code — one of the most popular code editors among developers — I have good news: in most cases, your code is not actually lost.
In this article, I'll show you how to use a native Visual Studio Code feature to recover lost files, even if you never made a Git commit.
The feature we'll use is called Local History, and it was officially introduced in VS Code version 1.66, released in March 2022.
The Solution
Local History keeps a local history of changes made to files edited in VS Code, allowing you to go back in time and restore previous versions of your code.
To recover a lost file, follow the steps below:
- Press F1
- Search for “Local History: Find Entry to Restore”
- After selecting the command, look for the name of the file you lost
- VS Code will display all saved versions of that file, along with timestamps of each change
- Select the desired version and click to restore the code
That's it. Your file will be restored exactly as it was at that point in time.
Important Notes About Local History
Before relying too much on this feature, it's important to understand its limitations:
- Local History is stored only locally, meaning it will be lost if you format your machine or clear VS Code data
- It does not replace Git and should not be used as a version control strategy
- The history has time and storage limits, so very old versions may be automatically removed
- It only works for files that were opened and edited inside VS Code
Best Practices to Avoid Losing Code
Even with this feature available, preventing these situations in the first place is always the best approach. Some good practices include:
- Make small, frequent commits
- Use branches for experiments and tests
- Avoid working for long periods without committing changes
- Always review what will be discarded before running destructive Git commands
Conclusion
VS Code is an extremely powerful code editor. It offers so many features and shortcuts that it's nearly impossible to know everything it can do. Local History is one of those lesser-known features that can make a huge difference.
If this article helped you recover lost code, consider sharing it with other developers. It might save someone's project — and sanity 😄