Reverting push to remote with sourcetree

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.

  • How to interactively (visually) resolve conflicts in SourceTree / git
  • Git Changes to file lost after merge with remote (SourceTree, GitHub)
  • How do I filter log by folder in SourceTree?
  • How to display datetime in SourceTree terminal bash
  • Long term support using git-flow to merge a hotfix to develop branched off the support branch
  • Sourcetree remote: Invalid username or password
  • I also found the rebase option, but I can’t seem to find a step-by-step tutorial..

    Any ideas?

  • private repo is getting cloned via ansible playbook but private gem are not getting installed
  • Python subprocess git checkout returns error even if there is no error
  • Undoing a git reset to uncommited state before reset?
  • GIT: Generated .bin symlinks prevent adding node_modules to repo
  • How to keep only head changes in a git rebase
  • Msys Git and Git on Ubuntu difference with the same repository
  • 2 Solutions collect form web for “Reverting push to remote with sourcetree”

    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.

    Sourcetree doesn’t expose the -f flag to you: https://answers.atlassian.com/questions/54469/how-do-i-perform-a-forced-push-push-f-from-sourcetree

    So, the only way to bring the remote back to it’s original state is to git revert each commit you introduced in the reverse order.

    Assuming the remote was on commit A and you pushed your feature branch holding commits B, C and D, you have to

    git revert D
    git revert C
    git revert B
    git push
    

    The push will work fine since you’re not modifying the pushed history but instead push a new set of changes.

    If you want to shorten your series of reverts to one commit, you could do a

    git rebase -i origin/master
    

    and select each of your revert commits to be squashed. Then, your push will only contain one commit that reverts D, C and B in one go.

    Git Baby is a git and github fan, let's start git clone.