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 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.
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
Videos
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.
I am working on a project on Visual Studio 2019. The last git push I did was 2 weeks back. After that I made 12 changes to the local repo on my computer. However I realised I made a mistake and want to go back to the same version I got pushed to the master repo 2 weeks back.
How do I undo all the changes made to the project since the last git push ?
I am using the git extension "Visual Studio git extension" in Visual Studio 2019.
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.
