Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 768
Ryan Shine Avatar asked Jul 25 '17 06:07

Ryan Shine


People also ask

How do I remove an incoming commit in git?

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits.

Does git reset delete commits?

The git revert command looks a lot like the reset command, and is also used to undo your changes in a project. We saw earlier how reset just wipes off data in your Git's state, and these commits are completely removed from the Commit History.

How do I remove a commit in Visual Studio?

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.

Does git reset hard remove local commits?

git reset --hard @{u} * deletes all your local changes on the current branch, including commits.


1 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.

like image 126
Reza Aghaei Avatar answered Sep 30 '22 13:09

Reza Aghaei