Windows 下配置 WinMerge 作为 Git 的比对工具

Why use WinMerge

  1. 免费开源(不像Beyond Compare 每年12刀(虽然有破解版但是总不放心))
  2. 真的好用(比自带的git diff 不知道好用多少)
  3. 还挺好看(?)

How to install WinMerge in git

  1. 官方仓库下载对应系统版本的WinMerge并安装(一路默认设置)
  2. 找到git配置文件.gitconfig ,windows用户一般在用户文件夹C:\Users\%username%下,如果你是别的系统就甭看了,没发现是Winmerge吗(逃
  3. 在其中加入如下配置
[diff]
tool = winmerge
[difftool "winmerge"]
cmd = "'C:/Program Files (x86)/WinMerge/WinMergeU.exe'" -e "$LOCAL" "$REMOTE"
[difftool]
prompt = false
[merge]
tool = winmerge
[mergetool "winmerge"]
cmd = "/c/Program\\ Files\\ \\(x86\\)/WinMerge/WinMergeU.exe" -u -e -wl -wr $LOCAL $BASE $REMOTE -o $MERGED
[mergetool]
keepBackup = true
trustExitCode =true

使用

比较差异

git difftool <file_name>

合并冲突

git mergetool

简化命令

实际使用过程中觉得命令太长,没有效率,可以给它们配置别名。

git config --global alias.dft difftool
git config --global alias.mgt mergetool

比如我就将 difftoolmergetool 配置了 dftmgt 这样的别名,使用的时候直接如下即可

git dft
git mgt

参考

use Winmerge inside of Git to file diff
Windows 下配置 Beyond Compare 作为 Git 的比对工具
Using WinMerge as the git Diff/Merge Tool on Windows 64bit