在Windows上使用Git:如何设置合并工具?
在Windows上使用Git:如何设置合并工具?
我已经尝试了 msysGit 和 Cygwin 上的 Git。它们本身都很好用,而且都能完美地运行 gitk 和 git-gui。
但现在我该怎么配置合并工具呢?(在Cygwin上Vimdiff可以用,但是我们中有些喜欢 Windows 的同事更喜欢一些更加用户友好的工具。)
admin 更改状态以发布 2023年5月21日
为了跟进Charles Bailey的答案,这是我使用
git config --global merge.tool p4merge git config --global mergetool.p4merge.cmd 'p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'
或者,在Windows cmd.exe shell中,第二行变成:
git config --global mergetool.p4merge.cmd "p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\""
更改(相对于Charles Bailey):
- 添加到全局git配置中,即对所有git项目有效而不仅仅是当前项目
- 自定义工具配置值驻留在“mergetool [tool].cmd”中,而不是“merge [tool].cmd”中(愚蠢的我,花了一个小时来调试git为什么始终在抱怨不存在的工具)
- 为所有文件名添加双引号,以便包含空格的文件也可以被合并工具找到(我在Powershell中的msys Git中进行了测试)
- 请注意,默认情况下,Perforce将其安装目录添加到PATH中,因此不需要在命令中指定p4merge的完整路径
下载:http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools
编辑 strong>(2014年2月) p>
正如@ Gregory Pakosz 所指出的,最新的msys git 现在“本地”支持p4merge strong>(在1.8.5.2.msysgit.0上进行测试)。
您可以运行以下命令显示支持的工具列表:
git mergetool --tool-help
您应该在可用或有效的列表中看到p4merge。如果没有,请更新您的git。
如果p4merge被列为可用,则它已经在您的PATH中,您只需设置merge.tool:
git config --global merge.tool p4merge
如果它被列为有效,则除了merge.tool之外,您还需要定义mergetool.p4merge.path:
git config --global mergetool.p4merge.path c:/Users/my-login/AppData/Local/Perforce/p4merge.exe
- 以上是当p4merge安装为当前用户而不是全局安装时的示例路径(不需要管理员权限或UAC提升)
- 虽然
~
应该扩展到当前用户的主目录(因此理论上路径应该是~/AppData/Local/Perforce/p4merge.exe
),但这对我不起作用 - 更好的方法是利用环境变量(例如
$LOCALAPPDATA/Perforce/p4merge.exe
),但git似乎不会为路径扩展环境变量(如果您知道如何使其工作,请告诉我或更新此答案)