I am trying to use the Visual Studio team explorer which is under Git. However, when I click
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...
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?
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.
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.
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.
git reset --hard @{u} * deletes all your local changes on the current branch, including commits.
You need to enable force push and then do a force push.
To do so, after doing a reset (delete changes):
Enable push --force
and click on Update
button.Push
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.
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