How to get rid of a failed merge?
Asked by Johan E. Bengtsson:

I am fairly new to SourceTree, so apologies if this question appears stupid... I have much more experience from using SVN and earlier CVS, but I think SourceTree works in a different way. I use SourceTree 1.8.3.0 under Windows 10. The central repository is at bitbucket.org .

I have a failed merge, showing in SourceTree as being based on two "branches", one representing my changes (not many), and another branch representing changes by another developer (not many) who probably edited emailed files and then committed them, before I realised that "commit" on its own does not "do that", so I made a push/merge that now reports conflicts.

How can I simply get rid of the merged version and back down to the changed files commtted by the other developer? Double-clicking the desired version advises me that I would get a "detached branch", and I am cautious about using branches for exactly the reason that it might create merge headaches like the current one. "Reset current branch to this commit" worked, but how can I now commit this version to be the current version in the central repository, instead of the version reported to have merge conflicts? I saw another question about "force push", but I do not find the mentioned "Allow force push" checkbox in preferences.

Can someone kindly advise me how to proceed with getting the central repository in a sane state again?  
[](https://community.atlassian.com/t5/Sourcetree-questions/How-to-get-rid-of-a-failed-merge/qaq-p/377318?attachment-id=12308){#link_1168bcc7d02d23}  
[](/tnckb94959/attachments/tnckb94959/sourcetree-questions/11196/1/image2016-10-28%207%3A44%3A25.png){#display_1168bcc7d02d23_0}  
[](https://community.atlassian.com/t5/Sourcetree-questions/How-to-get-rid-of-a-failed-merge/qaq-p/377318?attachment-id=12309){#link_1168bcc7d02d23_0}  
[](/tnckb94959/attachments/tnckb94959/sourcetree-questions/11196/2/image2016-10-28%207%3A46%3A12.png){#display_1168bcc7d02d23_2}


Answers:
author: Seth
body: Welcome to Git! I also came from a SVN/CVS background, and found the [Git Book](https://git-scm.com/book/en/v2) (online + free) very helpful in wrapping my head around the subtle but significant differences.

To get rid of your bad merge, there are three possibilities here, in order of simplicity:

1. If you did not push the merge, then resetting your current branch to an early commit is really all that is necessary.
2. If you did push the merge, and **this repo is the only clone of your butbucket repo**, then you can do a force push. To do so, check the "Force Push" box at the bottom of the push dialog.
3. If you pushed the merge, and there are other clones (especially if other people have cloned this repo), it gets complicated. You'll need to Pull to get your local branch in-sync with the remote (resetting to an early commit won't work). SourceTree doesn't revert merge commits, so you'll need to drop to the command line. <https://git-scm.com/blog/2010/03/02/undoing-merges.html>

comments: author: Johan E. Bengtsson
body: Thanks for your reply!

I reverted to the desired version and then made a force-push of it, this solved it. I had to update to the latest SourceTree version to get the preference checkbox where I could enable force-push.

Some other day I will figure out how to install git for use from Cygwin - I assume this is what you mean by "the command line".

I wish SourceTree had warned me about the merge-conflict when I made the earlier push (maybe it did, but it was not obvious enough).


author: Seth
body: Cygwin is not needed. SourceTree has installed Git in a MinGW environment already. Just hit the Terminal button in the upper right to launch it.

In regards to the conflict warning, your merge dialog looks like this when there are conflicts:

image2016-10-28 7:44:25.png

A successful merge will disappear automatically, unless you are showing the full output, which looks like this:

image2016-10-28 7:46:12.png


author: Seth
body: Also also, cygwin in general is no longer necessary for Windows 10. The anniversary edition includes a ubuntu-based bash shell (off by default): <http://www.howtogeek.com/265900/everything-you-can-do-with-windows-10s-new-bash-shell/>

apt-get install git


author: Johan E. Bengtsson
body: Thank you very much for helpful replies!

I don't think I got a warning about the merge conflicts until they were already there, and then I was already a bit stuck.

I tried installing BASH for Windows - what a usability hell! The colours used are terrible, and adjusting them is not easy at all. VI is pretty much unusable since the colours used have lousy contrast. I gave up, will instead use the Terminal window of Github and Cygwin. I might try BASH for Windows again later, once they reach usability that is better than what was available in the mid 1980ies on monochrome screens...


author: Seth
body: That's fine, use whatever terminal you want. In the past, I've frequently had significant problems getting cygwin functional, but if you had no problems getting it going, that's great.

I've never had SourceTree generate merge conflicts without warning me. Chances are the error dialog came up, and you closed it thinking the merge had failed, but then saw an uncommitted merge commit and figured the solution was obvious. Once the dialog is closed, conflicted files are marked with an exclamation icon in the file change list, but if you have you filter set to something besides "pending", they won't be shown, and SourceTree does NOT warn you about committing conflicts.


author: Johan E. Bengtsson
body: I just wanted to "check-in" my changes, so just did a "commit" - yeah, my previous experience from using CVS makes me a little confused about the separate merge/commit/push steps of GIT. It is conceivable that Windows 10 made an automatic reboot (yes a strong reason to avoid it), so I did not even see the merge/commit/push feedback.

I now select the option "Push to default/origin remote when comitting" and hope that this will make things work the way I expect it.

Thanks for your help!