Removing a bad merge on local and remote repository?

I'm working on a github branch off of master. Recently after merging master into my branch I did a commit and push to the remote repository, then discovered something bad happened during the merge. I don't know how to get past the bad merge that's now in the remote. I can reset my local repository to my previous good commit on my branch to continue work, but when I want to commit and push up to the remote repository, I can't because the remote is ahead of my local (by the bad commit). I can't pull from the remote because the bad commit messes up my local so I can't build. How do I recover from this?

3 answers

You probably won't be able to do this from the SourceTree UI, but you can definitely push the fix using the command line. I think the parameter is --force, but I would recommend a quick google search to confirm.

You have two options:

  1. Rewrite history: Do the changes as described and force push to the server (SourceTree does not seem to be able to do this, you need something else, e.g. cmd or GitExtensions.)
  2. Leave history as it is and fix the code: Revert the bad commit (since it is a merge commit, you need to either create a custom action in SourceTree to have the -m switch or do it from another client), push it to the server and commit on top of that as usual.

Thank you both for your suggestions. I ended up figuring out how to repair the code from the bad commit, and then checked in the repaired code.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

649 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you