VS Code Timeline Restores Lost Work That Git Can’t
Tags: development, git, programming, vscode
Published: 2022-09-27 18:28:33

---
title: VS Code Timeline Restores Lost Work That Git Can’t
published: true
tags: Development,git,programming,vscode
canonical_url: https://austingil.com/vs-code-timeline-restores-work-git-cant/
cover_image: https://austingil.com/wp-content/uploads/Command-Line-Blog-Cover.png
---

<iframe title="VS Code Trick To Restore Lost Work That Git Can't | Web Dev Office Hours" width="1290" height="726" src="https://www.youtube.com/embed/bI9-DuB1uIE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

If you’ve been working in web development for a while, you may run into scenarios where you make some changes or delete some files, and somehow lose work and a lot of time as a result.

Today I wanna show you some tips in VS Code to prevent that from happening.

The first thing you want to do when you need to modify a file is to copy and paste it, then rename the new file to “V2”. If you need more versions, you keep copy/pasting until you get to “V3”, “V4”, “V\_final”, then “V\_finalfinal”, and then “\_-this-time-for-real-final\_version\_V7”.

Just kidding :)

If you’ve been in the field a while and that brought up some deeply rooted trauma, I know a great therapist.

But technology has advanced enough that we don’t need to rely on that sort of format. We have tools like [Git](https://git-scm.com/), which has been around for a while and hopefully you’ve heard of it.

VS Code has some really nice Git integrations that [they have well documented](https://code.visualstudio.com/docs/sourcecontrol/overview). It allows you to:

- Take a snapshot of the current state of the project
- Shows you side by side comparison to see each change
- See changes from within a file
- Compare and revert changes in bulk, or one at a time

All of that is really nice, but that’s not what I wanted to show you.

In almost every single project that I’ve worked on, I’ve hit a point where I’ve committed some code and then actually wanted to go back and change some things about that commit.

Maybe I included files that should not have been there, or I forgot to include some changes that should have been in there.

I’ve always had to look up how you undo the most recent commit:

```
git reset --hard HEAD~1
```

I can never remember that, but the good news is I don’t have to.

VS Code has it built in. You can go to the source control tab, then in the little kebab menu, go to the “Commit” section and there’s an option to “Undo Last Commit”.

![VS Code screenshot with steps to undo last commit](https://cdn.statically.io/img/austingil.com/f=auto%2Cq=70/wp-content/uploads/undo-last-commitjpg.jpg)

That’s handy, but for the folks that prefer keyboard shortcuts, you can actually open up the command pallet with `ctrl+shift+P` (Windows) and search for “Undo Last Commit”. I usually just type “undo” and press “enter”. It’s really quick once you’re used to it.

Also pretty handy, but even that isn’t the coolest trick, because there are scenarios where Git is not actually going to help you.

Say, for example, that we actually added a `.gitignore` file to our project and we included a file we wanted to work on. That would exclude the file from version control. Which means we can’t make changes and then revert. This is a really common practice with something like ENV variables.

Now, if you accidentally delete this file, you better hope you have a backup.

You might be able to find it in the trash bin, but in my case, it actually goes straight to being deleted from disc. So it doesn’t exist in the trash bin. So how am I gonna get this back?

Fortunately, VS Code has this [Timeline view](https://code.visualstudio.com/updates/v1_44#_timeline-view), which is really, really cool because it will actually show you changes made to a file in between commit. You can think of it sort of like atomic version control.

![Screenshot of VS Code with a file open and a red box highlighting the Timeline for that file](https://cdn.statically.io/img/austingil.com/f=auto%2Cq=70/wp-content/uploads/vscode-timeline-1080x608.png)

It will show me the state of the file every time I hit save. It makes it really easy to go back and forth between versions.

And one of the coolest features here is if I delete a file, I can just create a new file with the same name and it will restore the timeline.

That feature has saved my butt a bunch of times (if you watch any of my [live streams](https://www.twitch.tv/heyaustingil), you know what I’m talking about).

That’s all I got. Now you can go out there and be as reckless with your code as you want.

Thank you so much for reading. If you liked this article, please [share it](https://twitter.com/share?via=heyAustinGil). It's one of the best ways to support me. You can also [sign up for my newsletter](https://austingil.com/newsletter/) or [follow me on Twitter](https://twitter.com/heyAustinGil) if you want to know when new articles are published.

* * *

_Originally published on [austingil.com](https://austingil.com/vs-code-timeline-restores-work-git-cant/)._ ![](https://bkit.co/w_6331abf4460ab.gif)