Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverting push to remote with sourcetree

Tags:

I accidently pushed a feature branch to the remote master. Now I want to revert the master to the previous commit. When I select 'Revert current branch to this commit' only the local branch is reverted, and because the remote master is 55 ahead (accidental push) I cannot push the just reverted local master to the remote.

When looking into this issue on SO and Google, I found that many people use force push using the command line. But since I'm using Source Tree I'd like to come up with a way that actually uses Source Tree.

I also found the rebase option, but I can't seem to find a step-by-step tutorial..

Any ideas?

like image 417
Michael Kloet Avatar asked Oct 27 '14 14:10

Michael Kloet


People also ask

How do I remove the last pushed commit in Sourcetree?

Assuming the just want to get rid of the last 2 commits, then you can right click on 3rd from last commit and choose "Reset current branch to this commit" and then decide if you want to keep any of the changed files or not, if not select the 'Hard' reset and your local repo will return to that state, before you ...


1 Answers

When you push a commit, the safest way to revert it (rather than forcing the push with -f) is to use the revert function, so a new commit is created on top of your previous commit.

This is possible to do using Sourcetree, right clicking in the commit that you want to revert, and selecting "Reverse commit...".

enter image description here

You would need to do this for each commit you want to revert, in reverse order.

like image 113
Jesús Carrera Avatar answered Dec 19 '22 19:12

Jesús Carrera