67

I regularly use Atlassian SourceTree (on Mac OS X) to launch FileMerge to resolve git merge conflicts. Out of the blue it has stopped working: when I right click and select Resolve Conflicts > Launch External Merge Tool, FileMerge launches, creates its intermediate files, then immediately exits. SourceTree interprets that as the merge process being complete.

What's the issue and how can I debug/fix it?

I note that a previous question 'SourceTree filemerge quits immediately and creates 4 files. How to fix it?' does not address this particular scenario (for one, it says FileMerge quits in the title, but in the body it says FileMerge displays /dev/null as one of the panels. Additionally, my merge conflict is not due to a removed file.)

1
  • try this on terminal and use SourceTree : "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer" Feb 13, 2019 at 20:02

7 Answers 7

181

To diagnose the problem, I ran opendiff from the Terminal. I received the following error:

xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

To solve:

  1. Open Xcode > Preferences > Locations
  2. Click on the drop-down box beside Command Line Tools and select your current Xcode version. (This was empty for me because I had recently installed Xcode on a new Mac.)

Command Line Tools

  1. Run opendiff in Terminal again, and the above error should no longer appear.

Now FileMerge will open correctly from SourceTree when you click Launch External Merge Tool.

7
  • 1
    Thanks, fixed the issue, It is still SourceTree's bug not to alert on the error, and to consider the file "merged" though. However, this Mac application is so bad - I don't even care to notify them about their bugs anymore. Nothing to expect there. Jan 3, 2019 at 9:32
  • @MottiShneor I agree that SourceTree should improve their user experience. This bug is already filed so feel free to up-vote it.
    – ChrisJF
    Jan 4, 2019 at 13:39
  • Thanks for the answer, it fixed my problem. It is unfortunate that SourceTree doesn't show any error dialog about this. May 3, 2019 at 8:56
  • 1
    Fixed mine too for Tower. My Xcode was not recently installed, but gets updated automatically and one of those updates left the Command Line Tools location empty. Had to quit both apps and then re-start Xcode and Tower (in that order). May 24, 2019 at 14:36
  • 1
    I love Stack Overflow. I was scouring the fork.io release notes looking for something on this. I forgot the golden rule: XCode is always the problem.
    – gyleg5
    Feb 6, 2020 at 21:45
22

For me, SourceTree didn't even launch FileMerge. When clicking Launch External Merge Tool nothing happened.

Moreover, running opendiff in Terminal worked as expected:

$ opendiff
opendiff[64176:5561154] too few arguments
opendiff[64176:5561154] usage: opendiff file1 file2 [-ancestor ancestorFile] [-merge mergeFile]

What helped me was manually configuring SourceTree to use FileMerge via the opendiff command with the following arguments: $LOCAL $REMOTE -ancestor $BASE -merge $MERGED

SourceTree manually configure to use opendiff

This way, SourceTree opens FileMerge as expected.

4
  • 2
    Same here, but i don't know why it didn't work when just set to file merge
    – MegaManX
    Jan 24, 2018 at 9:32
  • yup, this did it for me, finally, after a lot of trial and errors. If I just select diffmerge from the dropdown, it fails to launch external diff tool (ST shows a window saying that will need to close diff tool to return, but that window closes imediately). diffmerge was set correcly in .gitconfig, worked fine with "git mergetool" command, but I guess ST was ignoring that altogether Sep 26, 2019 at 17:14
  • I've had perpetual issues with this for many years. It has always been resolved by ensuring I agreed to the license agreement for xcode developer tools...until now. Your solution seems to do the trick this time. However, it did not work at first; I had to nuke my ~/.gitconfig file for some reason.
    – mrclary
    Feb 24, 2020 at 21:00
  • Update: It seems that the "FileMerge" selection in ST now works again. Perhaps I just needed to nuke my config file.
    – mrclary
    Feb 24, 2020 at 21:16
20

This helped: https://gist.github.com/kylefox/4512777

Tell system when Xcode utilities live:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

Set "opendiff" as the default mergetool globally:

git config --global merge.tool opendiff

2
  • 1
    That was it! the git config --global, thanks a lot!
    – Raffi
    Oct 15, 2020 at 12:19
  • xcode-select command is what solved it for me on Apple silicon. I had a location set in Xcode preferences, but it didn't seem to help.
    – Mike Post
    Mar 22 at 15:57
8

If Xcode has recently updated itself, you may need to agree to the new license terms. If you have not agreed to the license terms, FileMerge (when launched from SourceTree) will quit immediately.

To check for this, open a shell and run as your usual user:

$ opendiff

If the license is the problem, it will tell you. To agree to the new license terms, you'll need to run open diff using sudo:

$ sudo opendiff

After agreeing to the license terms, you can now retry launching FileMerge from SourceTree using Resolve Conflicts > Launch External Merge Tool. FileMerge should launch and behave normally.

2
  • 3
    It says opendiff xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
    – KarenAnne
    Dec 20, 2015 at 11:04
  • @Greg Kopff's thanks, your solution worked with me! :) In my case SourceTree was not openning FileMerge. I did update Xcode to 10.2.1 recently but I was using a previous active developer directory (see "xcode-select" terminal command) for still compiling some projects with Xcode 10.1 compiler. After setting the correct active developer directory again, "opendiff" runned ok and SourceTree was able again to open FileMerge. May 17, 2019 at 10:33
6

This also works to resolve the message "xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance":

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
2
  • 1
    i.e., make sure your xcode select is actually pointed at the /Contents/Developer subdir of an actual instance of Xcode. Helpful, thanks Sep 19, 2017 at 15:46
  • My instance does not have such a directory, any tips?
    – Matt
    Oct 4, 2017 at 17:24
2

Tick Allow Sourcetree to modify your global... solves the issue for me source tree preference

1
  • This was useful for me to fix the "visual diff tool" and "merge tool" options from being disabled. Check this box, change your tool, run a merge then uncheck this box (if you want to disable it)
    – Des
    Jul 13 at 11:41
0

I have encountered this problem and solved it with the answer here
So this time, when I had it again, I thought the same issue happened...

And after trying for almost an hour, I've realized that the Diffmerge (or any external diff tool) did not open because there was no file in the current branch to merge.

This can happen when you do Cherry Pick where the commits can be jumpy. Added this answer to remind people who are going to have the same issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.