Reverting to a previous commit in Git for visual studio 2012
C#.NetGitVisual StudioC# Problem Overview
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.
C# Solutions
Solution 1 - C#
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
Solution 2 - C#
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.
Solution 3 - C#
Well to those newbies who have the same problem, the best way not to waste 3 hours of your life is simply not to use visual studio tool for GIT. At least not in its current form.(23 Jun 2013)
After wasting much time i found out from an obscure link that the vs extension only supports a few of the GIT function with reset not being one of them.
Solution 4 - C#
In Team Explorer -> Branches
then select Actions -> Open command prompt
and use the git commands either:
- git checkout
your commit id
- git reset
your commit id
check this out to understand the difference https://stackoverflow.com/questions/3639342/whats-the-difference-between-git-reset-and-git-checkout
I think you'll also need to have git extension installed in Visual Studio, I have it, but not sure it's required to do that.