在 Windows 上为 Git 配置 diff 工具

发布于 2024-12-12 17:15:38 字数 672 浏览 3 评论 0 原文

由于 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 中呈现差异。

那么要让这个工作成功有什么技巧呢?

Since git diff in powershell mostly results in a unreadable amount of whitespace or strange characters, I installed Perforce P4Merge, to handle merging and diff.

However, I can't make git diff open the p4merge application to view the diff in. So far my .gitconfig looks like this:

[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

The paths are correct. But alas, git still attempts to present the diff in Powershell, when using git diff.

So what's the trick to make this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

小镇女孩 2024-12-19 17:15:39

在命令提示符中,尝试: git config --global diff.tool p4diff

这对我有用,使用您所描述的设置的配置文件:

[diff]  
    tool = p4merge  
[difftool "p4diff"]  
    external = '"C:/Program Files/Perforce/p4merge.exe" "$LOCAL" "$REMOTE"'

运行 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:

[diff]  
    tool = p4merge  
[difftool "p4diff"]  
    external = '"C:/Program Files/Perforce/p4merge.exe" "$LOCAL" "$REMOTE"'

Running git difftool opened p4merge as expected.

Ref: How do I view 'git diff' output with a visual diff program?

泅渡 2024-12-19 17:15:39

我在 Windows 7 上使用 MSysGit v1.8.4。

对我来说,唯一的解决方案是将 p4merge 添加到系统路径变量(之后需要重新启动)。完成此操作后,我像这样进行配置:

git config --global diff.tool p4merge
git config --global difftool.p4merge.cmd 'p4merge.exe $LOCAL $REMOTE'
git config --global difftool.prompt false

git config --global merge.tool p4merge
git config --global mergetool.p4merge.cmd 'p4merge.exe $BASE $LOCAL $REMOTE $MERGED'
git config --global mergetool.prompt false
git config --global mergetool.trustExitCode false
git config --global mergetool.keepBackup false

我建议您坚持使用“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:

git config --global diff.tool p4merge
git config --global difftool.p4merge.cmd 'p4merge.exe $LOCAL $REMOTE'
git config --global difftool.prompt false

git config --global merge.tool p4merge
git config --global mergetool.p4merge.cmd 'p4merge.exe $BASE $LOCAL $REMOTE $MERGED'
git config --global mergetool.prompt false
git config --global mergetool.trustExitCode false
git config --global mergetool.keepBackup false

I recommend you stick to "git config" instead of editing the conf manually because hyphens etc sometimes are different between these methods.

泪是无色的血 2024-12-19 17:15:39

我个人更喜欢与其他开源工具相比 meld 来进行 diff,

扩展@wengeezhang 答案,以下是将 Meld 配置为 difftool 的步骤。

  1. 将 Meld.exe 路径("C:\Program Files (x86)\Meld") 添加到环境路径
  2. 启动 Windows 命令提示符
  3. git config --global diff.tool meld
  4. git config -- global difftool.meld.cmd "meld \"$LOCAL\" \"$REMOTE\""

额外提示:
转到 Git 存储库的根目录并启动以下命令以并排查看所有差异

git difftool --dir-diff ./

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.

  1. Add Meld.exe path("C:\Program Files (x86)\Meld") to environment path
  2. Fire up windows command prompt
  3. git config --global diff.tool meld
  4. 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

git difftool --dir-diff ./
简单气质女生网名 2024-12-19 17:15:39

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.

你爱我像她 2024-12-19 17:15:39
  1. git config --global diff.tool p4merge
  2. git config --global difftool.p4merge.cmd "p4merge \"$LOCAL\" \"$REMOTE\""
  3. 添加 p4merge.exe 路径("C:\Program Files\Perforce\p4merge .exe") 到环境路径

ps:

  • 在步骤 2 中,您必须添加 \"$LOCAL\" \"$REMOTE\"(本地差异远程),否则 p4merge 将不知道要差异什么
  1. git config --global diff.tool p4merge
  2. git config --global difftool.p4merge.cmd "p4merge \"$LOCAL\" \"$REMOTE\""
  3. add p4merge.exe path("C:\Program Files\Perforce\p4merge.exe") to environment path

ps:

  • in step 2,you've to add \"$LOCAL\" \"$REMOTE\"(local diff remote),or p4merge won't know what to diff
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文