SourceTree external diff tool

The external diff tool in SourceTree (windows version) is not working at all. When system default is used, it tries to run vim.exe (presumably for vimdiff?), but nothing happens, vim.exe will just keep using the CPU resource until it's forced to terminate. Any other "out-of-the-box" tools I tried (kdiff3 and diffmerge) doesn't work as well. I tried looking at the sourcetree.exe.config, and found out that the difftool value is set to -1.

What is the correct way to setup a external difftool (and mergetool) for Window's SourceTree? Does it have to run under administrator privilege?

4 answers

1 accepted

'System default' means whatever you have configured in your .gitconfig already as your default diff tool. SourceTree doesn't change this one - it's there so that ST will by default just pick up anything you've already configured yourself - in your case you must have configured something to use vim at some point.

If you want SourceTree to configure a tool you should just be able to select the one of your choosing from the drop-down. I just tried Araxis, DiffMerge and KDiff3 here (I usually use P4Merge personally) and they all worked fine when I chose them. SourceTree doesn't run as admin, it runs as your own user but that should be enough to find things - when you pick a tool it searches for it by checking the registry (read-only) and also the common file locations (program files) - read only permissions should be fine.

If you still can't get this to work, please have a look at the .gitconfig file in your home directory, which is what ultimately gets used to open the external diff tool.

Thanks for the quick response.

1. Yes, I know the default is from git default. I didn't change anything for git diff, so it is vimdiff, and it works fine from gitbash.

2. I tried selecting kdiff3 and diffmerge, both doesn't do anything.

3. I just tried using the embedded git for sourcetree, still doesn't work.

I'm actually fine with using vimdiff, but the problem is it doesn't show up. It just loads the vim.exe in the background, and nothing else. So I figured I'd use something else, but it turns out they don't work.

I'm suspecting it is the sourcetree config that has problems. The "difftool" and "mergetool" setting in sourcetree.exe.config has a value set -1. Is this supposed to be the case?

  1. In that case it's probably a difference between the environment in Git Bash - anything you've set up there in your .profile etc, PATH, other environments, won't be visible when calling the difftool elsewhere. I've never used vimdiff though so I'm not sure of the specifics.
  2. Can you tell me where you have those tools installed, and whether they were installed via a regular installer or via something else like Cygwin which might not have registered them in a normal way in the registry? I have both tools installed here and they work fine, but I used their standard installers from their websites.

The value of -1 in the config is fine, it means 'System Default'. The SourceTree.exe.config alongside SourceTree.exe just defines the out-of-the-box settings, when you change any settings they get saved as 'user.config' under your %USERHOME%\AppData\Local folder (exactly where depends on which version you're using, the new installer puts them in Atlassian\SourceTree.exe_xxxxxx\versionno\user.config). So that's almost certainly not the issue.

I installed both kdiff3 and diffmerge using their regular installer.

I have cygwin, but I don't install vim there. In fact, the only vim I have is from git installation (under the share folder).

I tried to set gitbash to use kdiff as the difftool, works fine there, but still nothing from sourcetree.

Is there a path that I need to include or anything? If I were to uninstall git completely and use the embedded version, what will be the default diff tool?

Can I see your .gitconfig after you've configured kdiff yourself, and after you've configured it in SourceTree? ST actually creates an extra diff entry in parallel to your manually configured ones so we should just be able to compare them directly to see what the difference is.

[diff]
    tool = kdiff3
[difftool]
    prompt = false
[difftool "kdiff3"]
    path = C:/Program Files (x86)/KDiff3/kdiff3.exe
    trustExitCode = false

[merge]
    tool = kdiff3
[mergetool]
    keepBackup = false
[mergetool "kdiff3"]
    path = C:/Program Files (x86)/KDiff3/kdiff3.exe
    trustExitCode = false

Those are the settings I used. AFAIK, there is no change after I set ST to use kdiff3.

Thank you. That fixed it for me. I changed the HOME variable some time ago for cygwin, totally forgot to change that back.

AFAIK, there is no change after I set ST to use kdiff3

That probably explains why it's not working. What you should see is something like this after you configure anything other than 'System Default' in SourceTree:

[difftool "sourcetree"]
	cmd = 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
	cmd = 'C:/Program Files/Araxis/Araxis Merge/compare.exe' -wait -merge -3 \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"
	trustExitCode = true
	keepBackup = false

The fact that you don't have any entries like that suggests that the .gitconfig you're looking at isn't the one SourceTree is using. For that to happen, your command line must see a different .gitconfig - are you changing your HOME directory or other home-related settings in your bash .profile or similar, which is therfore only visible to bash? SourceTree uses the following rules to locate your global git config:

  1. HOME, if defined in the global Windows environment (NOT in .profile or similar, only Bash sees that)
  2. HOMEDRIVE + HOMEPATH as a first fallback
  3. USERPROFILE as a last resort

This is where it will be getting its settings from.

I installed Kdiff3 and set SourceTree to use Kdiff, but that seems to launch a two-way merge only. One of the things I really liked about Kdiff, which comes out of the box with TortoiseHq is that you get three way diffs.

We had a similar problem; our .gitconfig had two 'cmd' lines in the [difftool "sourcetree"] block. Git/SourceTree appeared to use the last 'cmd' assignment in the block, which was for some reason set to an unrelated command.

I am using Mercurial. In SourceTree > Options > Diff I can not change the setting under 'External Diff / Merge' at all, all the fields are disabled.

I want to set Winmerge as my Diff/Merge tool, how can I change that setting?

Found it! The option 'Allow SourceTree to modify your global Git and Mercurial config files' was unchecked. Checking this option enables the fields on the 'Diff' tab.

Hi.

I have the same issue : setting a diff/merge tool does not change the ST.config file. I have Tortoise Git installed, and I would like to use tortoiseGit Diff and Merge tools but no way...

I would preferer to avoid modifying the git config file if possible.

Did I miss something ?

Thanks :-)

Edit : When I set tortoise as tool, ST creates the merge file (in case of a conflict) (LOCAL, ETC...) but does not start any tool.

Same here... I have selected non-system default options for the external diff and merge and the ST.config file remains -1 on both cases

Suggest an answer

Log in or Join to answer
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 ...

262 views 0 3
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot