在 Windows 上为 Git 配置 diff 工具
由于 powershell 中的 git diff 通常会导致大量不可读的空格或奇怪字符,因此我安装了 Perforce P4Merge 来处理合并和比较。
但是,我无法让 git diff 打开 p4merge 应用程序来查看差异。到目前为止,我的 .gitconfig 看起来像这样:
[diff]
tool = p4diff
[difftool "p4diff"]
external = 'C:/PROGRA~1/Perforce/p4merge.exe "$LOCAL" "$REMOTE"'
prompt = false
[merge]
keepBackup = false
tool = p4merge
[mergetool "p4merge"]
cmd = "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
path = 'C:/PROGRA~1/Perforce/p4merge.exe'
prompt = false
keepBackup = false
keepTemporaries = false
trustExitCode = false
路径是正确的。但遗憾的是,当使用 git diff 时,git 仍然尝试在 Powershell 中呈现差异。
那么要让这个工作成功有什么技巧呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在命令提示符中,尝试:
git config --global diff.tool p4diff
这对我有用,使用您所描述的设置的配置文件:
运行
git difftool
打开p4merge 正如预期的那样。参考:如何使用可视化 diff 程序查看“git diff”输出?
In your command prompt, try:
git config --global diff.tool p4diff
That worked for me, using a config file set up as you had described:
Running
git difftool
opened p4merge as expected.Ref: How do I view 'git diff' output with a visual diff program?
我在 Windows 7 上使用 MSysGit v1.8.4。
对我来说,唯一的解决方案是将 p4merge 添加到系统路径变量(之后需要重新启动)。完成此操作后,我像这样进行配置:
我建议您坚持使用“git config”,而不是手动编辑配置,因为连字符等有时在这些方法之间是不同的。
I'm on Windows 7 using MSysGit v1.8.4.
For me, the only solution was to add p4merge to the system path variable (reboot needed afterwards). Having done this, I conf'd it like this:
I recommend you stick to "git config" instead of editing the conf manually because hyphens etc sometimes are different between these methods.
我个人更喜欢与其他开源工具相比 meld 来进行 diff,
扩展@wengeezhang 答案,以下是将 Meld 配置为 difftool 的步骤。
git config --global diff.tool meld
git config -- global difftool.meld.cmd "meld \"$LOCAL\" \"$REMOTE\""
额外提示:
转到 Git 存储库的根目录并启动以下命令以并排查看所有差异
I personally like meld better from other open source tools for just diff,
Expanding @wengeezhang answer, here is the step to configure Meld as difftool.
git config --global diff.tool meld
git config --global difftool.meld.cmd "meld \"$LOCAL\" \"$REMOTE\""
Bonus tip:
Go to Git repo's root directory and fire up following command to see all diff side by side
Dan Limerick 有一个关于在 Windows 上设置 Perforce 的 p4merge 的优秀简短教程:
http://danlimerick.wordpress.com/2011/06/19/git-for-window-tip-use-p4merge-as-mergetool/
使用 Git 1.9.4 和 p4merge 进行测试Windows 7 上的 2014.1。
Dan Limerick has an excellent short tutorial on setting up Perforce's p4merge on Windows:
http://danlimerick.wordpress.com/2011/06/19/git-for-window-tip-use-p4merge-as-mergetool/
Tested with Git 1.9.4 and p4merge 2014.1 on Windows 7.
ps:
ps: