How to remove an unpushed outgoing commit in Visual Studio?

Tony_Henrich picture Tony_Henrich · Nov 4, 2017 · Viewed 94.9k times · Source

I accidentally pushed a staged change in a new branch in Visual Studio 2017 to my local repository. It hasn't been pushed to the remote repository. I want to get rid of it but can't find a way to do this. I rebased from local master branch to the new branch. Then I deleted the new branch. But Outgoing Commits still shows it. How to delete it or revert it?

enter image description here

Answer

jessehouwing picture jessehouwing · Nov 4, 2017

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.