How can I make WinMerge my git mergetool?

GitWinmergeDifftoolMergetool

Git Problem Overview


I'm trying to integrate WinMerge with Git as I've seen others done before on Windows 7 Ultimate.

I've followed the following steps, but an error continues to show up when I do a git mergetool which defaults to vimdiff.

Created a file called winmerge.sh in the root directory of git: C/Program Files (x86)/Git/ with: WinMergeU is the correct location.

#!/bin/sh
echo Launching WinMergeU.exe: $1 $2
"C:/Program Files (x86)/WinMerge/WinMergeU.exe" 
git /e /u /dl "Base" /dr "Mine" "$1" "$2"

and used the following commands.

git config --global diff.tool winmerge
git config --global difftool.winmerge.cmd "winmerge.sh \"$LOCAL\" \"$REMOTE\""
git config --global difftool.prompt false

The error shows up as:

git config option merge.tool set to unknown tool: winmerge

Git Solutions


Solution 1 - Git

You are talking about merge tool, yet you (and some other people with answers) are configuring it as a diff tool.

To configure a merge tool, you'd need to use merge.tool and mergetool configurations instead of diff.tool and difftool, like this:

git config --global merge.tool winmerge
git config --replace --global mergetool.winmerge.cmd "\"C:\Program Files (x86)\WinMerge\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\""
git config --global mergetool.prompt false

And then you can use

git mergetool

which will open you the two files to edit.

Kudos for @dvdvck mentioning in the comments that in command line parameters you can specify a third file for the result file for winmerge (outputpath parameter).

For completeness, I'll mention that there is also this gist aimed at full configuration of winmerge for both as diff and merge tool.

Solution 2 - Git

If you decide to use SourceTree (or for any Google searchers with SourceTree), you can use WinMerge for the Merge Tool by setting the Merge Tool to custom, pointing Diff Command to WinMergeU.exe, typically:

C:\Program Files (x86)\WinMerge\WinMergeU.exe

In Arguments use:

-e -u -dl "Mine" -wr -dr "Theirs" $LOCAL $REMOTE $MERGED

That will cause the left side (labeled "Mine") to be editable and it will be the output file when you save in WinMerge. The right side (labeled "Theirs") will be read only (that's the -wr argument), this is needed because WinMerge outputs all saved files to the $MERGED file, so if both sides were edited, it would output the left side then overwrite that with the right side; best to avoid that kind of confusion.

If you leave the backup file option turned on, WinMerge will generate a .bak file. The contents of this file will either be the original left side file, or the second to last output file if you saved multiple times. You can either turn this off, or add *.bak to your .gitignore file.

Git itself will create a *.orig conflict file AFTER the conflict is resolved, just in case you botched it. Again, you can add *.orig to your .gitignore file or turn off this feature. Unfortunately, SourceTree does not have a GUI option for this, so fire up your git bash or, if you chose the right PATH option during installation, the Windows Command prompt and do this:

git config --global mergetool.keepBackup false

That will stop Git creating the *.orig files. You can also directly edit the config file by locating the .gitconfig file in the root of your user directory. If you know how to use VIM, you can edit the whole thing with this command:

git config --global --edit

Solution 3 - Git

Git 2.5+ (Q2 2015) will include Winmerge as a known git mergetool!

If Winmerge is in your %PATH%, a git config merge.tool winmerge is all you need to do!
(It works for diff tool too: git config diff.tool winmerge)

See commit 3e4f237 by David Aguilar (davvid), 20 May 2015.
(Merged by Junio C Hamano -- gitster -- in commit 324a9f4, 01 Jun 2015)
Helped-by: Philip Oakley (PhilipOakley), Johannes Schindelin (dscho), Sebastian Schuberth (sschuberth), SZEDER Gábor (szeder)

All the config is now done for you directly in Git itself, with mergetools/winmerge:

  • diff command: "$merge_tool_path" -u -e "$LOCAL" "$REMOTE"
  • merge command: "$merge_tool_path" -u -e -dl Local -dr Remote "$LOCAL" "$REMOTE" "$MERGED"

> ## mergetools: add winmerge as a builtin tool > > Add a winmerge scriptlet with the commands described in this thread, so that users can use winmerge without needing to perform any additional configuration.

Solution 4 - Git

Here's mine (in %userprofile%\.gitconfig, or ~/.gitconfig on *nix), no wrapper (Win 7 Home Pro):

[diff]
    tool = winmerge
[difftool "winmerge"]
    cmd = c:/path/to/winmergeu.exe -e -u -x -wl -wr -dl "base" -dr "mine" \"$LOCAL\" \"$REMOTE\"

Solution 5 - Git

This is easier to do and is what worked for me:

git config --global diff.tool winmerge

git config --replace --global difftool.winmerge.cmd "\"C:\path to winmerge\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" $LOCAL $REMOTE"

git config --global difftool.prompt false

Solution 6 - Git

To do WinMerge as compare and merge tool for Visual Studio 2017 Git Plugin:

From windows command prompt: type >> git config --global --edit which will open the .getconfig file to edit.

Please update with below command:

[mergetool]
   prompt = false
   keepBackup = false
   keepTemporaries = false
[merge]
   tool = winmerge
   [mergetool "winmerge"]
   name = WinMerge
   trustExitCode = true
   cmd = \"C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
[diff]
   tool = winmerge
   [difftool "winmerge"]
   name = WinMerge
   trustExitCode = true
   cmd = \"C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" -u -e $LOCAL $REMOTE

Solution 7 - Git

I originally upvoted @CapinWinky's answer for using WinMerge from SourceTree. That answer is still valid, but WinMerge now also supports a three-way merge which needs additional parameters.

Within the SourceTree Options dialog I chose "Custom" as the Merge Tool, entered the command as:

C:\Program Files\WinMerge\WinMergeU.exe

and the Arguments as:

-u -fm -wl -wr -dl Remote_RO -dm Local_Merged -dr Base_RO $REMOTE $LOCAL $BASE -o $MERGED

It doesn't seem to be necessary to enclose the remote/local/base parameters in quotes to cater for paths with spaces in them any more.

This configuration is for using the middle pane as the merged output file.

Command line reference

I had the problem that when trying to merge, WinMerge wouldn't open. Sourcetree starts Git to open your tool of choice. When using Sourcetree's custom option, your git config file (e.g. C:\Users\Me\.gitconfig) is modified to add a new Merge tool called "sourcetree" and the Git command includes --tool=sourcetree . At some point the .gitconfig file hadn't been updated correctly and I had two 'cmd' lines in that section, one being broken:

[mergetool "sourcetree"]
	cmd = 'C:/Program Files/WinMerge/WinMergeU.exe' -u -fm -wl -wr -dl Remote_RO -dm Local_Merged -dr Base_RO $REMOTE $LOCAL $BASE -o $MERGED
	trustExitCode = true
	cmd = 'C:/Program '

Manually fixing up the .gitconfig file sorted the problem.

Solution 8 - Git

Your path is incorrect, it should be "/c/Program Files (x86)/WinMerge/WinMergeU.exe".

You're running in a shell script environment, not native windows command prompt.

Solution 9 - Git

Entering the settings via the command line has been covered by other answers. The .gitconfig file for full 3-way merging with WinMerge could be configured like this (this example is from Windows):

[merge]
	tool = WinMerge
	
[mergetool "WinMerge"]
	cmd = \"C:\\Program Files\\WinMerge\\WinMergeU.exe\" -e -u -dl \"Local\" -dm \"Base\" -dr \"Remote\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" -o \"$MERGED\"
	trustExitCode = true
	keepBackup = false

[diff]
	tool = WinMerge
	
[difftool "WinMerge"]
	cmd = \"C:\\Program Files\\WinMerge\\WinMergeU.exe\" -e -u -dl \"Old $BASE\" -dr \"New $BASE\" \"$LOCAL\" \"$REMOTE\"
	trustExitCode = true

Flag information:

  • /e - Allows WinMerge to be closed via a single press of the 'esc' key.
  • /u - Prevents WinMerge from logging the files in the recently used list.
  • /dl, /dm, and /dl - Descriptions for Left, Middle, and Right panes.
  • /o - The output file. Saving ANY pane will output that pane's contents to the output file.

trustExitCode = true tells git to accept the output without further prompt.

keepBackup = false will automatically delete the automatically generated *.orig files.

Note: The $BASE and $MERGE variables when using difftool both simply contain the filename.

Solution 10 - Git

After installing TortoiseGit and WinMerge 2.16 (this version supports 3-way merging), I found how WinMerge integrate itself to TortoiseGit:

D:\Program Files\WinMerge\WinMergeU.exe /e /ub /fm /wl /wr /dl %tname /dm %bname /dr %yname  %theirs %base %mine /o %merged /am

So I edited the .gitconfig file and change some vars to make it work for me (I added WinMerge dir to the system path):

[mergetool "winmerge"]
    cmd = WinMergeU -e -ub -fm -wl -wr $LOCAL $BASE $REMOTE -o $MERGED -am

Solution 11 - Git

After hassling with this for over an hour, I installed tortoisegit and so far it's giving me exactly what I want.

Settings of Winmerge for Tortoise git are described in http://thoai-nguyen.blogspot.com.au/2012/03/setup-tortoise-git-and-winmerge.html

Solution 12 - Git

Example:

git config --global --add diff.tool winmerge
git config --replace --global difftool.winmerge.cmd "\"C:\Program Files (x86)\WinMerge\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" $LOCAL $REMOTE"
git config --global difftool.prompt false

Solution 13 - Git

Here the only one working for me with Visual Studio 2019 and my winmerge 2.16.14.0: C:\Users\CurrentUserAccount\.gitconfig

[difftool "winmerge"]
name = WinMerge
trustExitCode = true
	cmd = \"C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" -e -u  \"$LOCAL\" \"$REMOTE\"
[diff]
	tool = winmerge
[difftool]
	prompt = false

Additional thing to check: file MySolution.git\config (yes, the file name is "config" without extension): Verify if you have:

[diff]
tool = winmerge

You can modify it with the following command (Visual studio Menu "Git"\Open in Command Prompt":

git config diff.tool winmerge

Solution 14 - Git

So, I've never used a three-window-mode for merging and was able to configure everything with help above but as nowadays with a Winmerge 2.16.16.0 I was able to get desired behavior only with 'Open conflict File' option. The git config for it is:

cmd = \"c:/Programs/WinMerge/WinMergeU\" -e $MERGED

As for me this it is the best speed/usability option without manual handling of those special markers ...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWei JinView Question on Stackoverflow
Solution 1 - GiteisView Answer on Stackoverflow
Solution 2 - GitCapinWinkyView Answer on Stackoverflow
Solution 3 - GitVonCView Answer on Stackoverflow
Solution 4 - GitellothethView Answer on Stackoverflow
Solution 5 - GitgmanView Answer on Stackoverflow
Solution 6 - GitZin MinView Answer on Stackoverflow
Solution 7 - GitDazView Answer on Stackoverflow
Solution 8 - GitThach MaiView Answer on Stackoverflow
Solution 9 - GitCapinWinkyView Answer on Stackoverflow
Solution 10 - GittrankView Answer on Stackoverflow
Solution 11 - Gitandersonbd1View Answer on Stackoverflow
Solution 12 - GitzumalifeguardView Answer on Stackoverflow
Solution 13 - GitOlivier ChatagnonView Answer on Stackoverflow
Solution 14 - GitAlexander RozinovView Answer on Stackoverflow