bash 使用 p4merge 作为 git diff 工具

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32152446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:29:11  来源:igfitidea点击:

Using p4merge as git diff tool

gitbashversion-controlwindows-7p4merge

提问by hasanghaforian

I use windows 7. I want to use p4mergeas Git diff/merge tool. I follow this articleand this oneto setup and config p4merge:

我用windows 7. 我想p4merge用作 Git diff/merge 工具。我按照这篇文章这一个安装和配置p4merge

git config --global merge.tool p4merge
git config --global mergetool.p4merge.path "C:/Program Files/Perforce/p4merge.exe"
git config --global diff.tool p4merge
git config --global difftool.p4merge.path "C:/Program Files/Perforce/p4merge.exe"

And these lines are from git config:

这些行来自git config

merge.tool=p4merge
mergetool.p4merge.path=C:/Program Files/Perforce/p4merge.exe
diff.tool=p4merge
difftool.p4merge.path=C:/Program Files/Perforce/p4merge.exe
mergetool.keeptemporaries=false
mergetool.prompt=false

Now git mergetoolcommand works fine. But when I use git difftoolcommand in git bash, I expect p4mergebut I see internal implementation of diff in git bash.

现在git mergetool命令工作正常。但是当我使用git difftool的命令git bash,我希望p4merge,但我看到实现了diff git bash

I tried Smooth Git + P4mergebut it does not work for me also I tried to do as described in External Merge and Diff Toolsbut I did not understand that.

我尝试了Smooth Git + P4merge但它对我不起作用,我也尝试按照外部合并和差异工具中的描述进行操作,但我不明白这一点。

Note:

笔记:

When type of conflict is removed file conflict, git difftoolcommand opens p4merge.

当冲突类型为 时removed file conflictgit difftool命令打开p4merge

采纳答案by Kohányi Róbert

Not sure if helps, but recent versions of Git support P4Merge (I use git version 2.17.0.on Windows through MSYS2).

不确定是否有帮助,但最近版本的 Git 支持 P4Merge(我git version 2.17.0.通过 MSYS2 在 Windows 上使用)。

You can tell if this is the case or not by running git difftool --tool-help. It'll list the available tools Git can use (because they've found them in your %PATH%) and the tools it coulduse (if they were installed).

您可以通过运行来判断是否是这种情况git difftool --tool-help。它将列出 Git 可以使用的可用工具(因为他们已经在您的 中找到了它们%PATH%)以及它可以使用的工具(如果它们已安装)。

If p4mergeis in this list then you just need to add the path where p4merge.exeresides to your %PATH%(on Windows I recommend Rapid Environment Editorfor this).

如果p4merge在此列表中,那么您只需要添加p4merge.exe您所在的路径%PATH%(在 Windows 上,我为此推荐使用Rapid Environment Editor)。

After this is done you just need the following config to be in your .gitconfig

完成此操作后,您只需要以下配置即可 .gitconfig

[diff]
    tool = p4merge
[merge]
    tool = p4merge

and nothing else. So remove other stuff like difftool.pathand all that.

没有别的。所以删除其他类似的东西difftool.path

Then just use git difftoolor git mergetoolto your hearts content.

然后只需使用git difftoolgit mergetool满足您的需求。

Note: I had a repository in which even if I did issue the git difftoolor git mergetoolcommands P4Merge wouldn't start. I'm not sure what was the problem in that repo. However I tried creating an empty repo somewhere on my drive with git init, add a file, commit it, then modify it, thenI tried difftooland it worked. So if the above description doesn't work for you chances the problem lies somewhere else. Hope this helps.

注意:我有一个存储库,即使我确实发出了git difftoolgit mergetool命令,P4Merge 也不会启动。我不确定那个 repo 中的问题是什么。但是我尝试在我的驱动器上的某处创建一个空的 repo git init,添加一个文件,提交它,然后修改它,然后我尝试difftool并且它起作用了。因此,如果上述描述对您不起作用,那么问题可能出在其他地方。希望这可以帮助。

回答by Csharpfunbag

Better late than never :)

迟到总比不到好 :)

mergetool.p4merge.path should be mergetool.p4merge.cmd

mergetool.p4merge.path 应该是 mergetool.p4merge.cmd

Change path to cmd for both the mergetool and difftool lines.

将 mergetool 和 difftool 行的路径更改为 cmd。