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.
Use the git reset Command to Remove Unpushed Commits in Git. Whenever we want to commit changes to the project directory, we can commit the changes using the git add and git commit commands. When using the git commit command, a commit is created in the local Git repository.
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.
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:
master
master
remotes/origin
Use git reset --soft HEAD~
in the cmd from the .sln folder
I was facing it today and was overwhelmed that VSCode
suggests such thing, whereas its big brother Visual Studio
doesn't.
Most of the answers weren't helpful; if I have more commits that were made before, losing them all would be frustrating.
Moreover, if VSCode
does it in half a second, it shouldn't be complex.
Only jessehouwing's answer was the closest to a simple solution.
Go to Team Explorer
-> Sync
.
There you'd see the all the commits. Press the Actions
dropdown and Open Command Prompt
You'll have the cmd window prompted, there write git reset --soft HEAD~
.
If there are multiple undesired commits, add the amount after the ~
(i.e git reset --soft HEAD~5
)
(If you're not using git
, check colloquial usage).
I hope it will help, and hopefully in the next version VS team will add it builtin
Assuming you have pushed most recent changes to the server:
Once you reopen the project both commits and changes should be zero.
You have 2 options here to do that either to discard all your outgoing commits OR to undo specific commit ..
1- Discard all your outgoing commits:
To discard all your outgoing commits For example if you have local branch named master from remote branch, You can:
1- Rename your local branch from master to anything so you can remove it. 2- Remove the renamed branch. 3- create new branch from the master
So now you have a new branch without your commits ..
2- Undo specific commit: To undo specific commit you have to revert the unneeded by:
1- Double click on the unneeded commit. Double click on the unneeded commit 2- Click on revert Click on revert
But FYI the reverted commit will appear in the history of your commits with the revert commit ..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With