Skip to content

Setting Up DiffMerge

JoeBrockhaus edited this page Feb 3, 2016 · 7 revisions

Setting up Diff and Merge for Git command line

Go to your C:\Users\<username>\ directory. There will probably already be a .gitconfig file located there. If not, create one. That file is "global" to all your local repositories.

Open the file in Notepad, and add the following section:

[diff]
	tool = vsdiffmerge
[difftool]
	prompt = true
[difftool "vsdiffmerge"]
	cmd = \"vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
	keepbackup = false
	trustexistcode = true
[merge]
	tool = vsdiffmerge
[mergetool]
	prompt = true
[mergetool "vsdiffmerge"]
	cmd = \"vsdiffmerge.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" //m
	keepbackup = false
	trustexistcode = true

This will ensure that when you use the command line, the Visual Studio diff/merge tool will be used, and you should avoid the dreaded ">>>HEAD" tags in your files.

NOTE1: This require that VS is in your path. It should be for VS command prompts, and Action command line, but if you get issues here, add the full path which shoule be something like %VSINSTALLDIR%Common7\IDE\vsdiffmerge.exe

[difftool "vsdiffmerge"]
cmd = "'%VSINSTALLDIR%Common7/IDE/vsdiffmerge.exe' $LOCAL $REMOTE //t "
keepbackup = false
trustexistcode = true
[mergetool "vsdiffmerge"]
cmd = "'%VSINSTALLDIR%/Common7/IDE/vsdiffmerge.exe' $REMOTE $LOCAL $BASE $MERGED //m "
keepbackup = false
trustExitCode = true

Thanks to Gian Maria Ricci for the discussions about this, see his blogpost about this, and you can download his setup here.

Setting up Diff and Merge for SourceTree

The commands above will not affect the SourceTree application. SourceTree supports Beyond Compare, KDiff3 and a bunch of others Out-Of-The-Box. But if you want the Visual Studio diffmerge tool to open up when using SourceTree, follow the instructions below:

To set the same there, open up Tools/Options and choose the Diff tab.

Set the tools as shown below:

The line to add to the Diff Arguments is:

$LOCAL $REMOTE //t

The line to add to the Merge Arguments is:

$REMOTE $LOCAL $BASE $MERGED //m

Running an externally initiated merge

If you do a merge initiated externally, f.ex. SourceTree - by f.e. doing a Pull which starts up the merge you will be taken into the merge conflict resolver in Visual Studio.

Be aware that you WILL be shown an ugly file in that process, it will look like this:

Note the ugly markers, BUT just ignore this file, press the "Resolve the conflict" link upper left, and continue with the Merge resolution - you will be taken - after a few more clicks - to the merge resolution tool.

Fixing a possible Merge Commit bug in VS

After you have fixed the conflict, you press the Commit Merge in the dialog shown below.

IF: When you press this, it doesn't seem to do anything, it is press-able, but that is all, then you have stumbled into a VS 2013 bug - I have reported it, awaiting resolution.

To fix this, go to SourceTree and commit the merge from there (faster than command line, saves you the comment writing). It will be shown as Uncomitted changes", so just press the Commit button, and it should come up as this:

Then just push it up!