DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Mastering GitHub Copilot in VS Code: Ask, Edit, Agent and the Build–Refine–Verify Workflow
  • Let’s Build an End-to-End NFT Project Using Truffle Suite
  • Use the Truffle Suite for Easy WEB3 - And Earn Your POAP
  • 3 Easy Steps for a (Dev)Containerized Microservice With Jolie and Docker

Trending

  • Introducing TypeSafe Jev: Typed Judgments as Programming Primitives
  • Modernizing a Legacy Java Application With OpenRewrite: What We Automated and What We Didn't
  • Measuring AI Impact at the Team Level
  • Building an AI-Powered Code Review Assistant in Java

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Tools
  4. VS Code Timeline Restores Lost Work That Git Can’t

VS Code Timeline Restores Lost Work That Git Can’t

VS Code Timeline can take snapshots of different save points of a file. This can help you save lost work that Git may not be able to.

By 
Austin Gil
DZone Core CORE ·
Sep. 29, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
9.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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, 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. 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:

Shell
 
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

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. This means we can’t make changes and then revert. This is 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 the 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, which is really, really cool because it will actually show you changes made to a file in between commits. You can think of it sort of like atomic version control.

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, 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. It's one of the best ways to support me. You can also follow me on Twitter if you want to know when new articles are published.

Git Timeline Virtual screening Visual Studio Code

Published at DZone with permission of Austin Gil. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Mastering GitHub Copilot in VS Code: Ask, Edit, Agent and the Build–Refine–Verify Workflow
  • Let’s Build an End-to-End NFT Project Using Truffle Suite
  • Use the Truffle Suite for Easy WEB3 - And Earn Your POAP
  • 3 Easy Steps for a (Dev)Containerized Microservice With Jolie and Docker

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook