Is there a way to revert to a previous commit in VS code?

GitVisual Studio-Code

Git Problem Overview


I googled it but was unable to find the answer to the question.

Thanks in advance.

P.S I know I can see the changes between commits and the differences in the working tree but I want to know how to reset to the previous commit in visual studio code

Git Solutions


Solution 1 - Git

With the source control icon selected, if you then click the ellipsis ... at the top right.

With v1.48 you will see a list of options for submenus: under Commit is Undo Last Commit. Under Changes is Discard All Changes.

git submenus

Solution 2 - Git

Provided that you have GitLens extension installed you should be able to simply select "Restore" action from selected "File history" commit.

GitLens Restore file from File History

Solution 3 - Git

I use GitLens for that:

  1. In the source control tab, open File History.
  2. Choose your commit, then right-click Commit.
  3. Click on Revert Commit....

enter image description here

Solution 4 - Git

You can use this option in the Gitlens "commits" section to reset any number of previous (local) commits: just right click on the commit you would like to reset your current local branch

enter image description here

Then a list appears to allow you to choose a suitable reset option, as usual:

enter image description here

In recent vscode (1.51.1 currently installed) Gitlens extension has been integrated in the source control side view, by the way, instead of having its own button in the sidebar as before.

Solution 5 - Git

In vscode press Ctrl + Shift + P, type git undo, and hit Enter.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVikranthView Question on Stackoverflow
Solution 1 - GitMarkView Answer on Stackoverflow
Solution 2 - GitjmarceliView Answer on Stackoverflow
Solution 3 - GitIdan DaganView Answer on Stackoverflow
Solution 4 - Gitm.arditoView Answer on Stackoverflow
Solution 5 - GitAnasView Answer on Stackoverflow