Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get rid of a failed merge?

Johan E. Bengtsson October 27, 2016

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?

1 answer

0 votes
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 27, 2016

Welcome to Git! I also came from a SVN/CVS background, and found the Git Book (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

 

Johan E. Bengtsson October 27, 2016

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).

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2016

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

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2016

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

Johan E. Bengtsson October 29, 2016

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...

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2016

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.

Johan E. Bengtsson October 31, 2016

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!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events