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

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

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.
git - Is there a way to revert to a previous commit in VS code? - Stack Overflow
git reset - How can I undo pushed commits using Git? - Stack Overflow
How do I undo an accidental Git Commit in VS ?
git - Possible to undo a commit in Visual Studio? - Stack Overflow
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.

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

You can revert individual commits with:
git revert <commit_hash>
This will create a new commit which reverts the changes of the commit you specified. Note that it only reverts that specific commit, and not commits that come after that. If you want to revert a range of commits, you can do it like this:
git revert <oldest_commit_hash>..<latest_commit_hash>
It reverts all the commits after <oldest_commit_hash> up to and including <latest_commit_hash>. Some versions of git also revert the <oldest_commit_hash> itself, so double check if that commit gets reverted or not. You can always drop the latest revert commit (which reverts the oldest commit) with g reset --hard HEAD~.
To find out the hash of the commit(s) you can use git log.
Look at the git-revert man page for more information about the git revert command. Also, look at this answer for more information about reverting commits.
Extra note for re-applying reverted commits:
Usually you revert commits because you discovered the commits that you pushed turn out to have an issue. Then you first want to restore the repo to a stable state, before you continue to fix the issue. So then you would first do the git revert, as described before. Then push those revert commits, so the remote is stable. After that you would want to re-apply the reverted commits locally, so your local repo's files are back to the state before the revert. Then you can fix the issue.
To re-apply the reverted commits, you have to revert the revert commits. So what you would do, is to again execute the git revert command, but then with the range of commits of the revert commits. So your new revert commits will revert the previous revert commits. Then your files are back to the state before the first revert. Then you can fix the issue, create a new commit with the fix, and then push all the new commits.
A solution that keeps no traces of the "undo".
NOTE: Don't do this if someone already pulled your change (I would use this only on my personal repo.)
Run:
git reset <previous label or sha1>
Note: previous means the commit before the erroneous commit
This will re-checkout all the updates locally (so git status will list all updated files, meaning, the files you changed/added/.. and were committed).
Then you "do your work" and re-commit your changes (Note: This step is optional).
git commit -am "blabla"
At this moment your local tree differs from the remote
git push -f <remote-name> <branch-name>
will force the remote branch to take this push and remove the previous one (specifying remote-name and branch-name is not mandatory but is recommended to avoid updating all branches with update flag).
!! Watch-out some tags may still be pointing removed commit !! how-to-delete-a-remote-tag
Visual Studio 2019 (16.8.1)
I accidentally did a Git commit on the wrong branch.
I can’t figure out how too ‘undo’ it so that I can stash the changes for the correct branch.
You were just about there:
I opened up Git > Manage Branches and see the commit i did and see a couple of options.
You'll want to learn more about the different git reset options and how they work, but the two reset options that Visual Studio offers are --mixed and --hard. To use the reset option, in the branch history graph, select the commit that you wish to reset your branch pointer to, and this will remove all of the commits above it (and if a merge commit is being removed it will also remove all commits brought in by that merge).
For your use case where you have one commit that you wish to remove, and re-commit some of it, select the parent commit of that commit (the one below your commit in the graph), right click on it, and select "Reset->Keep Changes (--mixed)". This will put you back into the state you were in before you created the commit, with nothing staged yet.
Side Notes:
- If you don't want to keep any of your changes, you should choose
--hard. - Note that VS doesn't offer the option to do a
--softreset in the GUI, but the only difference with--softis that all your changes would be staged already, which you can manually do in the GUI after reset with--mixed. - The GUI command is identical to running the following command from the command line, e.g. a mixed reset:
git reset --mixed <selected-commit-id>
You can effect an undo from within VS, but it's not an actual undo, it's a compensating commit that reverts you back to the prior state of the offending commit.
From the Search dropdown in the main menu select Feature Search. Type in View History or View Branch History and select that. A history of your commits will be listed. Right click the commit you want to undo and choose Revert.
I'd show a screenshot but I'd have to redact everything.
Selected answer is not correct. In order to undo a commit you need to select reset, not revert. Revvert will make a new commit with code contained in previous commit. Where reset will actually delete the commits after the selected version.
Open the "Changes" tab in Team Explorer. Select "Actions", then "View History" to view the history of the repository. Identify the commit that you want to revert, right-click on it and select "Revert" from the context menu.

Open the history tab in Team Explorer from the Branches tile (right-click your branch). Then in the history right-click the commit before the one you don't want to push, choose Reset. That will move the branch back to that commit and should get rid of the extra commit you made. In order to reset before a given commit you thus have to select its parent.

Depending on what you want to do with the changes choose hard, which will get rid of them locally. Or choose soft which will undo the commit but will leave your working directory with the changes in your discarded commit.
I could not find a single good answer that helped me get rid of this issue.
Let's say the name of branch, you accidentally committed changes to, is master. Following four simple steps proved like a world to me:
- Go to Branches
- Choose or create any branch other than
master - Delete local/workspace version of
master - Switch to master from
remotes/origin