How can I make WinMerge my git mergetool?

2019-01-10 06:28发布

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

9条回答
Fickle 薄情
2楼-- · 2019-01-10 06:52

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
查看更多
\"骚年 ilove
3楼-- · 2019-01-10 06:55

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
查看更多
【Aperson】
4楼-- · 2019-01-10 06:55

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

查看更多
姐就是有狂的资本
5楼-- · 2019-01-10 07:04

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
查看更多
Lonely孤独者°
6楼-- · 2019-01-10 07:10

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
查看更多
三岁会撩人
7楼-- · 2019-01-10 07:12

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.

查看更多
登录 后发表回答