我在Cygwin上尝试了msysGit和Git。两者都能很好地完成它们并且完美地运行gitk和git-gui。
现在我如何配置合并工具? (Vimdiff在Cygwin上工作,但最好是我希望我们的一些喜欢Windows的同事更方便用户使用。)
答案 0 :(得分:294)
对Charles Bailey的回答进行跟进,这是我使用p4merge(免费的跨平台3way合并工具)的git设置;在msys Git(Windows)安装上测试:
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):
下载: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 上测试)
您可以通过运行以下方式显示支持的工具列表:
git mergetool --tool-help
您应该在可用或有效列表中看到 p4merge 。如果没有,请更新您的git。
如果 p4merge 列为 available ,则它位于 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
~
应该扩展到当前用户的主目录(理论上路径应该是~/AppData/Local/Perforce/p4merge.exe
),但这对我不起作用$LOCALAPPDATA/Perforce/p4merge.exe
),git似乎不会扩展路径的环境变量(如果你知道如何使这个工作,请告诉我或更新此答案)答案 1 :(得分:87)
设置mergetool.p4merge.cmd将不再起作用,因为Git已经开始尝试支持p4merge,请参阅libexec / git-core / git-mergetool--lib.so我们只需要为git指定mergetool路径,例如p4merge:
git config --global mergetool.p4merge.path 'C:\Program Files\Perforce\p4merge.exe'
git config --global merge.tool p4merge
然后它会起作用。
答案 2 :(得分:58)
我在WinXP上使用Portable Git(有效!),需要解决分支中出现的冲突。在我检查过的所有gui中,KDiff3被证明是最透明的。
但我在this blog post中找到了使其在Windows中运行所需的说明,这些说明与此处列出的其他方法略有不同。它基本上等于将这些行添加到我的.gitconfig
文件中:
[merge]
tool = kdiff3
[mergetool "kdiff3"]
path = C:/YourPathToBinaryHere/KDiff3/kdiff3.exe
keepBackup = false
trustExitCode = false
现在工作得很好!
答案 3 :(得分:20)
在Cygwin下,对我有用的唯一事情如下:
git config --global merge.tool myp4merge
git config --global mergetool.myp4merge.cmd 'p4merge.exe "$(cygpath -wla $BASE)" "$(cygpath -wla $LOCAL)" "$(cygpath -wla $REMOTE)" "$(cygpath -wla $MERGED)"'
git config --global diff.tool myp4diff
git config --global difftool.myp4diff.cmd 'p4merge.exe "$(cygpath -wla $LOCAL)" "$(cygpath -wla $REMOTE)"'
另外,我想关闭difftool的提示信息:
git config --global difftool.prompt false
答案 4 :(得分:16)
git mergetool
完全可配置,因此您几乎可以选择自己喜欢的工具。
完整文档在此处:http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html
简而言之,您可以通过设置用户配置变量merge.tool
来设置默认的mergetool。
如果合并工具是本机支持的合并工具之一,则只需将mergetool.<tool>.path
设置为该工具的完整路径(将<tool>
替换为您配置的merge.tool
是。
否则,您可以将mergetool.<tool>.cmd
设置为在运行时进行eval的shell,并将shell变量$BASE, $LOCAL, $REMOTE, $MERGED
设置为相应的文件。无论是直接编辑配置文件还是使用git config
命令设置变量,都必须小心转义。
这样的事情应该能够提供你能做的事情('mymerge'是一个虚构的工具)。
git config merge.tool mymerge
git config merge.mymerge.cmd 'mymerge.exe --base "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"'
一旦您设置了自己喜欢的合并工具,只需在遇到要解决的冲突时运行git mergetool
即可。
Perforce的p4merge工具是一个非常好的独立合并工具。
答案 5 :(得分:6)
在Windows 7上进行超越比较
git config --global merge.tool bc3
git config --global mergetool.bc3.path "C:\Program Files (x86)\Beyond Compare 3\BCompare.exe"
答案 6 :(得分:6)
似乎新的git版本直接支持p4merge,所以
git config --global merge.tool p4merge
如果p4merge.exe在您的路径上,则应该只需要。无需设置cmd或路径。
答案 7 :(得分:5)
答案 8 :(得分:4)
我不得不在Windows 7上使用msysGit删除额外的引用,不知道原因。
git config --global merge.tool p4merge
git config --global mergetool.p4merge.cmd 'p4merge $BASE $LOCAL $REMOTE $MERGED'
答案 9 :(得分:3)
我使用名为WinMerge的应用程序(http://winmerge.org/) 手册中的信息(http://manual.winmerge.org/CommandLine.html)
这是我通过mergetool
.gitconfig
指令使用的bash脚本
#!/bin/sh
# using winmerge with git
# replaces unix style null files with a newly created empty windows temp file
file1=$1
if [ "$file1" == '/dev/null' ] || [ "$file1" == '\\.\nul' ] || [ ! -e "$file1" ]
then
file1="/tmp/gitnull"
`echo "">$file1`
fi
file2=$2
if [ "$file2" == '/dev/null' ] || [ "$file2" == '\\.\nul' ] || [ ! -e "$file2" ]
then
file2="/tmp/gitnull"
`echo "">$file2`
fi
echo diff : $1 -- $2
"C:\Program files (x86)\WinMerge\WinMergeU.exe" -e -ub -dl "Base" -dr "Mine" "$file1" "$file2"
基本上bash在空文件中考虑diff的结果,并在正确的位置创建一个新的临时文件。
答案 10 :(得分:3)
Bah,这个终于为我工作了(Windows 7 + Cygwin + TortoiseMerge):
在.git / config中:
cmd = TortoiseMerge.exe /base:$(cygpath -d \"$BASE\") /theirs:$(cygpath -d \"$REMOTE\") /mine:$(cygpath -d \"$LOCAL\") /merged:$(cygpath -d \"$MERGED\")
感谢之前的海报提示使用cygpath!
答案 11 :(得分:3)
如果您是通过cygwin执行此操作,则可能需要使用cygpath:
git config --global merge.tool p4merge
git config --global mergetool.p4merge.cmd 'p4merge `cygpath -w $BASE` `cygpath -w $LOCAL` `cygpath -w $REMOTE` `cygpath -w $MERGED`'
答案 12 :(得分:2)
我找到了两种方法来配置&#34; SourceGear DiffMerge &#34;在github Windows中作为difftool和mergetool。
命令提示符窗口中的以下命令将更新.gitconfig以配置GIT使用DiffMerge:
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe \"$LOCAL\" \"$REMOTE\"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe -merge -result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"'
[或强>
将以下行添加到.gitconfig中。此文件应位于C:\ Users \ UserName:
中的主目录中[diff]
tool = diffmerge
[difftool "diffmerge"]
cmd = C:/Program\\ Files/SourceGear/Common/DiffMerge/sgdm.exe \"$LOCAL\" \"$REMOTE\"
[merge]
tool = diffmerge
[mergetool "diffmerge"]
trustExitCode = true
cmd = C:/Program\\ Files/SourceGear/Common/DiffMerge/sgdm.exe -merge -result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
答案 13 :(得分:1)
您可能也想要添加这些选项:
git config --global merge.tool p4mergetool
git config --global mergetool.p4merge.cmd 'p4merge $BASE $LOCAL $REMOTE $MERGED'
git config --global mergetool.p4mergetool.trustExitCode false
git config --global mergetool.keepBackup false
另外,我不知道为什么,但米尔加迪安的回答中的引用和斜线对我来说搞砸了。
答案 14 :(得分:1)
如果有人想在TortoiseGit上使用gvim作为他们的差异工具,那么你需要输入外部差异工具路径的文本输入:
path\to\gvim.exe -f -d -c "wincmd R" -c "wincmd R" -c "wincmd h" -c "wincmd J"
答案 15 :(得分:1)
对于IntelliJ IDEA(Community Edition)Windows环境中的3路git mergetool配置(~/.gitconfig
)
Cygwin
[mergetool "ideamerge"]
cmd = C:/Program\\ Files\\ \\(x86\\)/JetBrains/IntelliJ\\ IDEA\\ Community\\ Edition\\ 14.1.3/bin/idea.exe merge `cygpath -wa $LOCAL` `cygpath -wa $REMOTE` `cygpath -wa $BASE` `cygpath -wa $MERGED`
[merge]
tool = ideamerge
<强> MSYS 强>
[mergetool "ideamerge"]
cmd = "/c/Program\\ Files\\ \\(x86\\)/JetBrains/IntelliJ\\ IDEA\\ Community\\ Edition\\ 14.1.3/bin/idea.exe" merge `~/winpath.sh $LOCAL` `~/winpath.sh $REMOTE` `~/winpath.sh $BASE` `~/winpath.sh $MERGED`
[merge]
tool = ideamerge
〜/ winpath.sh是在msys上将路径转换为Windows,取自msys path conversion question on stackoverflow
#! /bin/sh
function wpath {
if [ -z "$1" ]; then
echo "$@"
else
if [ -f "$1" ]; then
local dir=$(dirname "$1")
local fn=$(basename "$1")
echo "$(cd "$dir"; echo "$(pwd -W)/$fn")" | sed 's|/|\\|g';
else
if [ -d "$1" ]; then
echo "$(cd "$1"; pwd -W)" | sed 's|/|\\|g';
else
echo "$1" | sed 's|^/\(.\)/|\1:\\|g; s|/|\\|g';
fi
fi
fi
}
wpath "$@"
答案 16 :(得分:0)
要设置p4merge,在windows上使用chocolatey安装merge和diff,请看一下: https://gist.github.com/CamW/88e95ea8d9f0786d746a
答案 17 :(得分:0)
如果您在从SourceTree打开p4merge时遇到问题,请在MyRepo.git下查找名为 config 的本地配置文件,并删除任何合并配置。 在我的情况下,它试图打开我刚刚卸载的Meld
答案 18 :(得分:0)
对于kdiff3,您可以使用:
git config --global merge.tool kdiff3
git config --global mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
git config --global mergetool.kdiff3.trustExitCode false
git config --global diff.guitool kdiff3
git config --global difftool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
git config --global difftool.kdiff3.trustExitCode false