How to get rid of incoming commits after doing a git Reset in Visual Studio? (Delete remote commits)

Viewed 7670

I am trying to use the Visual Studio team explorer which is under Git. However, when I click enter image description here

this and I can go back to my previous version, it unable to because there is incoming commits back to where the latest wrong version again...

enter image description here

I tried to click revert and does not help me to going back to the previous version again. Can anyone help how to going back to previous version without have incoming commit?

2 Answers

You need to enable force push and then do a force push.

To do so, after doing a reset (delete changes):

  • Go to Team Explorer → Settings → Git → Global Settings and check Enable push --force and click on Update button.
  • Go to Team Explorer → Branches → Right click on your local branch and choose Push
  • A message box will appear showing a warning asking you would you like to overwrite remote commits? Select Yes.

Warning

Usually you need to revert changes which simply means undo changes and commit this undo as well. So you have both the change and the undo commit in history.

But sometimes for some reason, you want to get rid of few last commits without having them in remote history (WARNING). So you can reset those few commits and delete changes. Now your local branch is behind the remote branch and there are several incoming commits. Then you can do a force push to overwrite remote commit history by your local history.

Do this carefully, just when you understand what you are doing, is overwriting remote history. Don't do it on a branch which is shared between multiple people.

Related