Shane Bartholomeusz

Geek and lover of all things tech related

Quick Tip: VS Code Restore Previous File Version

Overview

Have you ever found yourself in a situation where you’ve modified a local code file and needed to revert back to a previously saved local version that was not committed to your Git repo?

If you’re a user of Visual Studio Code you’re in luck because I’ll show you how to do just that …

VS Code Icon

Quick Tip

Whilst exploring the myriad of menu options and panels available in VS Code … I recently stumbled upon a little-known feature of Visual Studio Code called the “timeline” which displays a running history of a given file.

You can find it by opening a given file in VS Code and towards the bottom of the File Explorer menu you will notice a panel called “TIMELINE” which displays the running version history of a given file. It displays your local file save history (uncommitted changes) and Git repo commits all in one place. It’s a very hand, yet little-known feature of VS Code.

Clicking the entries in the Timeline panel will show a diff comparison of the changes made.

Visual Studio Code Screenshot

One important thing to note is that the local file save history will only be tracked if you edit the file using VS Code. Therefore if you edit the file outside of VS Code you will not see any file version history.

Final Thoughts

Visual Studio Code sometimes can make you feel like a kid in a candy store … there are so many flashing lights and knobs to turn that it can sometimes become a little bit overwhelming. I often feel like I’m barely scratching the surface of its extensive feature set. With that said, I hope you’ve learned something new about Visual Studio Code from this post.

If you have any other VS Code tips you wish to share. Feel free to post them in the comments below to help other developers out there.

Happy coding! 🙂

Shane Bartholomeusz

2 Comments

  1. Thanks, super helpful, i tried git fsck >> git show, git reflog, git checkout head < > but nothing worked.

    Also, for restoring deleted files:

    Open VSCode’s command palette and type “Local History” and select “Local History: Find Entry to Restore.”
    A list of all files you have worked in the repository will be displayed included the deleted files. Select the deleted file name you are looking for and click on the “select tick mark” which appears on the right side corner of the screen which says “restore the contents”.

  2. Thanks, it was helpful!

Leave a Reply

© 2024 Shane Bartholomeusz

Theme by Anders NorenUp ↑