Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverting to a previous commit in Git for visual studio 2012

I am really new to git and source control.

I am using visual studio tools for git with vs2012.

I am on some commit and want to go back to some previous commit but i cannot seem to do it how. When i go to the commit details the revert button seems to have been grayed out.

I have stuck on this problem for the last 2 hours. I have researched the internet but to no use. Please can somebody tell me how to revert to a previous commit.

Thanks.

like image 883
Win Coder Avatar asked Jun 23 '13 06:06

Win Coder


People also ask

How do I revert to a previous commit in git Visual Studio?

The original commit is still in the Git history. To do the same in Visual Studio, right-click the commit you want to revert and then select Revert. After you confirm your action and the operation is complete, Visual Studio displays a success message and a new commit appears in the Outgoing section.

Can I go back to a specific commit in git?

Steps to revert a Git commitLocate the ID of the commit to revert with the git log or reflog command. Issue the git revert command and provide the commit ID of interest. Supply a meaningful Git commit message to describe why the revert was needed.

How do I undo a committed change in Visual Studio code?

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


2 Answers

Visual Studio 2015 Update 2 adds support for GIT "Reset", which is what you probably want to do:

  • open history
  • right click the commit you want to revert to
  • reset -> reset and delete changes

GIT Reset in Visual Studio 2015 Update 2

like image 174
Runar Jordahl Avatar answered Sep 21 '22 12:09

Runar Jordahl


You don't want to do a revert - revert just takes a commit and undoes it.

If you want to go back to a previous commit - there are two options:

If you want to permanently go back, do a git hard reset, which rolls back the code to a specified commit. You can do this via:

git reset --hard {commit number} 

If you want to temporarily go back, you can create a branch from that commit. which will essentially keep you current path in the code history, and create another path from the point in history where that code was committed.

like image 45
Oved D Avatar answered Sep 21 '22 12:09

Oved D