43

I have the following in my .gitconfig file:

[user]
    name = myname
    email = myname@gmail.com
[core]
    autocrlf = true
    excludesfile = C:\\Users\\myname\\Documents\\gitignore_global.txt
[diff]
        tool = meld
[difftool "meld"]
        cmd = "C:/Program Files (x86)/Meld/meld/meld.exe"
        prompt = false
[merge]
        tool = meld

[mergetool "meld"]
        cmd = "C:/Program Files (x86)/Meld/meld/meld.exe"
[difftool "sourcetree"]
    cmd = "C:/Program Files (x86)/Meld/meld/meld.exe $PWD/$LOCAL $PWD/$BASE $PWD/$REMOTE"
[mergetool "sourcetree"]
    cmd = 'C:/Program Files (x86)/Meld/meld/meld.exe' \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
    trustExitCode = true

And in Sourcetree, I have the following settings:

Enter image description here

However, when I right-clicked a file on Sourcetree to do an external diff, I was able to open Meld, but the contents of the file were not displayed at all.

Enter image description here

What have I done wrong in the settings?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mynameisJEFF
  • 4,073
  • 9
  • 50
  • 96

5 Answers5

45

I feel the existing answers slightly missed the point. Here is my own dog food:

Enter image description here

Arguments Detail:

Diff:  $LOCAL $REMOTE
Merge: $LOCAL $BASE $REMOTE --auto-merge --output=$MERGED

For External Diff, you need to remove $BASE from your argument list.

For 3-way merging, you need to click on the External Merge Tool option instead, which will only be available if there are any unsolved conflicts.

Context menu of External Merge Tool

If you are not restricted to Sourcetree + Meld, I reckon the Git Extensions + KDiff3 suite could be a good open-sourced alternative also.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Paris Qian Sen
  • 1,020
  • 10
  • 21
  • BTW, according to others, the Meld "3-way comparison" is not a actual 3-way merging, because a 3-way merging requires 4 windows: base, local, remote, merged – Paris Qian Sen Aug 16 '16 at 02:12
  • 6
    You should paste the args into your answer. It isn't clear if there is more arguments in the latter example. Such as: `$LOCAL $BASE $REMOTE --auto-merge --output=$MERGED` – Jonathan Sep 29 '16 at 17:38
  • So, should the arguments be those in the screenshot or in the text? – Andrew Jan 26 '18 at 07:00
  • @Andrew The one in the text is more detailed. – Paris Qian Sen Jan 29 '18 at 01:17
24

The actual setting to use here in order to have a real 3-way merge, with read only THEIRS and MINE tabs is this:

$LOCAL $BASE $REMOTE --auto-merge --output=$MERGED

Note the = after --output.

I've finally got this command right by digging in comments on the second answer to this question Git merging using Meld.

Community
  • 1
  • 1
Jozef Legény
  • 1,157
  • 1
  • 11
  • 26
19

For OS X it looks like this:

  • Diff Command: /Applications/Meld.app/Contents/MacOS/meld.

    • Arguments: $LOCAL $REMOTE
  • Merge Command: /Applications/Meld.app/Contents/MacOS/meld.

    • Arguments: $LOCAL $BASE $REMOTE --auto-merge --output=$MERGED

P.S. you might have to configure the order of $local and $ remote in meld prefrences as well..

To use it from command line you have to install it via brew: brew install meld

Sourcetree preferences pane

Aman Satija
  • 1,865
  • 2
  • 15
  • 16
skywinder
  • 21,291
  • 15
  • 93
  • 123
  • 5
    Using a prebuilt Meld.app from [https://github.com/yousseb/meld/releases/] I needed to set the Diff Command to: `/Applications/Meld.app/Contents/MacOS/meld` – SteveS May 18 '17 at 18:19
  • 1
    Didn't work out of the box for me. needed to use: `$LOCAL $REMOTE` for diff arguments. – robertdavid Jun 07 '17 at 15:47
  • 1
    I had to do `brew tap homebrew/cask`, and then `brew cask install meld` in order to install it on OSX. Testing it now, thanks! – facundofarias Sep 19 '18 at 08:28
  • Why are you using `@LOCAL` and `@REMOTE` ?? Shouldn't it be `$LOCAL` and `$REMOTE` ?? – 7wp Sep 18 '19 at 14:38
  • if install via brew,the diff and merge command i used is : /usr/local/bin/meld on my osx,this can work – jack jin Dec 30 '20 at 00:23
2

Try adding the location of meld.exe to your PATH (e.g. C:\Program Files (x86)\Meld), and then in the Diff Command, just enter meld instead of the full path. See the gist How to use meld with Sourcetree on Windows.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
redlus
  • 2,301
  • 2
  • 12
  • 16
2

If you don't want to modify the PATH environment variable, you can use the DOS-compatible short names:

C:\Progra~1 = C:\Program Files
C:\Progra~2 = C:\Program Files (x86)

That avoids the trouble-causing spaces in the path and plays nice with Sourcetree. It's hackish, but it works. You can then use something like this as the path to Meld:

C:\Progra~1\Meld\meld.exe

It may not be guaranteed that Progra~1 maps to the 64-bit directory, so you might need to experiment with which one maps to which.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
pmont
  • 2,083
  • 22
  • 43