Windows 上的 Git:如何设置合并工具?
我在 Cygwin 上尝试过 msysGit 和 Git。 两者本身都工作得很好,并且都完美地运行 gitk 和 git-gui。
现在我到底该如何配置合并工具呢? (Vimdiff 可以在 Cygwin 上运行,但我希望对于一些喜欢 Windows 的同事来说,它能更加用户友好。)
I've tried msysGit and Git on Cygwin. Both work just fine in and of themselves and both run gitk and git-gui perfectly.
Now how the heck do I configure a mergetool? (Vimdiff works on Cygwin, but preferably I would like something a little more user-friendly for some of our Windows-loving coworkers.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
为了跟进 Charles Bailey 的答案,这是我使用 p4merge(免费的跨平台 3way 合并工具); 在 msys Git (Windows) 安装上进行测试:
或者,从 Windows cmd.exe shell 中,第二行变为:
更改(相对于 Charles Bailey):
下载:http://www.perforce.com/product /components/perforce-visual-merge-and-diff-tools
编辑(2014 年 2 月)
正如 @Gregory Pakosz,最新的msys git 现在“原生”支持p4merge(在 1.8.5.2.msysgit.0 上测试)。
您可以通过运行以下命令来显示支持的工具列表:
您应该在可用或有效列表中看到p4merge。 如果没有,请更新你的 git。
如果p4merge被列为可用,那么它就在您的PATH中,您只需设置merge.tool:
如果它被列为有效,除了merge.tool之外,您还必须定义mergetool.p4merge.path:
~
应该扩展到当前用户的主目录(因此理论上路径应该是~/AppData/Local/Perforce/p4merge.exe
),这对我来说不起作用$LOCALAPPDATA/Perforce/p4merge.exe),git 似乎没有扩展路径的环境变量(如果您知道如何使其工作,请让我知道或更新此答案)
To follow-up on Charles Bailey's answer, here's my git setup that's using p4merge (free cross-platform 3way merge tool); tested on msys Git (Windows) install:
or, from a windows cmd.exe shell, the second line becomes :
The changes (relative to Charles Bailey):
Download: http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools
EDIT (Feb 2014)
As pointed out by @Gregory Pakosz, latest msys git now "natively" supports p4merge (tested on 1.8.5.2.msysgit.0).
You can display list of supported tools by running:
You should see p4merge in either available or valid list. If not, please update your git.
If p4merge was listed as available, it is in your PATH and you only have to set merge.tool:
If it was listed as valid, you have to define mergetool.p4merge.path in addition to merge.tool:
~
should expand to current user's home directory (so in theory the path should be~/AppData/Local/Perforce/p4merge.exe
), this did not work for me$LOCALAPPDATA/Perforce/p4merge.exe
), git does not seem to be expanding environment variables for paths (if you know how to get this working, please let me know or update this answer)设置 mergetool.p4merge.cmd 将不再起作用,因为 Git 已经开始尝试支持 p4merge,请参阅 libexec/git-core/git-mergetool--lib. 所以我们只需要指定 git 的 mergetool 路径,例如 p4merge:
然后它就会起作用。
setting mergetool.p4merge.cmd will not work anymore since Git has started trying to support p4merge, see libexec/git-core/git-mergetool--lib.so we just need to specify the mergetool path for git,for example the p4merge:
Then it will work.
我在 WinXP 上使用 Portable Git(很好用!),并且需要解决分支中出现的冲突。 在我检查过的所有 gui 中,KDiff3 被证明是使用起来最透明的。
但我在 这篇博文,说明与此处列出的其他方法略有不同。 它基本上相当于将这些行添加到我的
.gitconfig
文件中:现在工作正常!
I'm using Portable Git on WinXP (works a treat!), and needed to resolve a conflict that came up in branching. Of all the gui's I checked, KDiff3 proved to be the most transparent to use.
But I found the instructions I needed to get it working in Windows in this blog post, instructions which differ slightly from the other approaches listed here. It basically amounted to adding these lines to my
.gitconfig
file:Working nicely now!
在 Cygwin 下,唯一对我有用的事情如下:
另外,我喜欢关闭 difftool 的提示消息:
Under Cygwin, the only thing that worked for me is the following:
Also, I like to turn off the prompt message for difftool:
git mergetool
是完全可配置的,因此您几乎可以选择自己喜欢的工具。完整的文档在这里: http://www.kernel .org/pub/software/scm/git/docs/git-mergetool.html
简而言之,您可以通过设置用户配置变量
merge.tool
来设置默认合并工具。如果合并工具是其本机支持的工具之一,您只需将< /code> 您已配置的
mergetool..path
设置为该工具的完整路径(替换merge.tool
否则,您可以将
mergetool..cmd
设置为要 eval 的一些 shell'在运行时将 shell 变量$BASE、$LOCAL、$REMOTE、$MERGED
设置为适当的文件,无论是直接编辑配置文件还是设置,都必须小心转义。使用git config
命令的变量应该能体现出您可以做什么(“mymerge”是一个虚构的工具)
。每当有冲突需要解决时,运行 git mergetool 就可以了
Perforce 的 p4merge 工具是一个非常好的独立合并工具。
git mergetool
is fully configurable so you can pretty much chose your favourite tool.The full documentation is here: http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html
In brief, you can set a default mergetool by setting the user config variable
merge.tool
.If the merge tool is one of the ones supported natively by it you just have to set
mergetool.<tool>.path
to the full path to the tool (replace<tool>
by what you have configuredmerge.tool
to be.Otherwise, you can set
mergetool.<tool>.cmd
to a bit of shell to be eval'ed at runtime with the shell variables$BASE, $LOCAL, $REMOTE, $MERGED
set to the appropriate files. You have to be a bit careful with the escaping whether you directly edit a config file or set the variable with thegit config
command.Something like this should give the flavour of what you can do ('mymerge' is a fictional tool).
Once you've setup your favourite merge tool, it's simply a matter of running
git mergetool
whenever you have conflicts to resolve.The p4merge tool from Perforce is a pretty good standalone merge tool.
在 Windows 7 上无与伦比
For beyond compare on Windows 7
似乎较新的 git 版本直接支持 p4merge,所以
如果 p4merge.exe 在您的路径上,那么这应该是您所需要的。 无需设置cmd或路径。
It seems that newer git versions support p4merge directly, so
should be all you need, if p4merge.exe is on your path. No need to set up cmd or path.
我发现有两种方法可以在 github Windows 中将“SourceGear DiffMerge”配置为 difftool 和 mergetool。
命令提示符窗口中的以下命令将更新您的 .gitconfig 以使用 DiffMerge 配置 GIT:
[OR]
将以下行添加到您的 .gitconfig。 该文件应位于您的主目录 C:\Users\UserName 中:
I found two ways to configure "SourceGear DiffMerge" as difftool and mergetool in github Windows.
The following commands in a Command Prompt window will update your .gitconfig to configure GIT use DiffMerge:
[OR]
Add the following lines to your .gitconfig. This file should be in your home directory in C:\Users\UserName:
正如此处已经回答的那样(以及此处和此处),mergetool是配置它的命令。 对于一个漂亮的图形前端,我推荐 kdiff3 (GPL)。
As already answered here (and here and here), mergetool is the command to configure this. For a nice graphical frontend I recommend kdiff3 (GPL).
我不得不在 Windows 7 上使用 msysGit 删除额外的引用,不知道为什么。
I had to drop the extra quoting using msysGit on windows 7, not sure why.
如果您通过 cygwin 执行此操作,则可能需要使用 cygpath:
If you're doing this through cygwin, you may need to use cygpath:
啊,这终于对我有用(Windows 7 + Cygwin + TortoiseMerge):
在.git/config中:
感谢之前的海报提供了使用cygpath的提示!
Bah, this finally worked for me (Windows 7 + Cygwin + TortoiseMerge):
In .git/config:
Thanks to previous posters for the tip to use cygpath!
我使用一个名为 WinMerge 的应用程序 ( http://winmerge.org/ )
来自他们的手册的信息( http://manual.winmerge.org/CommandLine.html )
这是我通过
.gitconfig
从mergetool
指令使用的 bash 脚本基本上说明了 bash 何时将 diff 的结果放入空文件中,并以正确的方式创建新的临时文件地点。
i use an app called WinMerge ( http://winmerge.org/ )
info from their manual ( http://manual.winmerge.org/CommandLine.html )
this is the bash script i use from the
mergetool
directive via.gitconfig
basically the bash accounts for when the result of the diff in an empty file and creates a new temp file in the correct location.
您可能也想添加这些选项:
另外,我不知道为什么,但米兰加迪安答案中的引用和斜杠把事情搞砸了。
You may want to add these options too:
Also, I don't know why but the quoting and slash from Milan Gardian's answer screwed things up for me.
如果有人想使用 gvim 作为 TortoiseGit 上的 diff 工具,那么您需要在文本输入中输入外部 diff 工具的路径:
If anyone wants to use gvim as their diff tool on TortoiseGit, then this is what you need to enter into the text input for the path to the external diff tool:
对于 IntelliJ IDEA(社区版)Windows 环境中的 3 路 git mergetool 配置(
~/.gitconfig
)Cygwin
Msys
~/winpath。 sh 是在msys上将路径转换为Windows,取自stackoverflow上的msys路径转换问题
For IntelliJ IDEA (Community Edition) 3-way git mergetool configuration in Windows environment (
~/.gitconfig
)Cygwin
Msys
The ~/winpath.sh is to convert paths to Windows on msys and is taken from msys path conversion question on stackoverflow
对于 kdiff3 你可以使用:
For kdiff3 you can use:
要设置p4merge,在Windows上使用chocolatey安装用于合并和比较,请看这里:
https://gist.github.com/CamW/88e95ea8d9f0786d746a
To setup p4merge, installed using chocolatey on windows for both merge and diff, take a look here:
https://gist.github.com/CamW/88e95ea8d9f0786d746a
如果您在从 SourceTree 打开 p4merge 时遇到问题,请在 MyRepo.git 下查找名为 config 的本地配置文件,并删除所有合并配置。
就我而言,它试图打开我刚刚卸载的 Meld
If you're having problems opening p4merge from SourceTree look for you local configuration file named config under MyRepo.git and delete any merge configuration.
In my case it was trying to open Meld which I just uninstalled