我在Cygwin上尝试了msysGit和Git。两者本身都工作得很好,并且都能完美地运行gitk和git-gui。
现在我该如何配置合并工具呢?(Vimdiff在Cygwin上工作,但我更希望能有一个对我们一些喜欢windows的同事更友好的东西。)
我在Cygwin上尝试了msysGit和Git。两者本身都工作得很好,并且都能完美地运行gitk和git-gui。
现在我该如何配置合并工具呢?(Vimdiff在Cygwin上工作,但我更希望能有一个对我们一些喜欢windows的同事更友好的东西。)
当前回答
我找到了两种方法来配置“SourceGear DiffMerge”作为difftool和github Windows中的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\"'
[OR]
将以下行添加到.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\"
其他回答
为了跟进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\""
变化(相对于查尔斯·贝利):
added to global git config, i.e. valid for all git projects not just the current one the custom tool config value resides in "mergetool.[tool].cmd", not "merge.[tool].cmd" (silly me, spent an hour troubleshooting why git kept complaining about non-existing tool) added double quotes for all file names so that files with spaces can still be found by the merge tool (I tested this in msys Git from Powershell) note that by default Perforce will add its installation dir to PATH, thus no need to specify full path to p4merge in the command
下载:http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools。
编辑(2014年2月)
正如@Gregory Pakosz所指出的,最新的msysgit现在“本地”支持p4merge(在1.8.5.5.2 .msysgit.0上测试)。
您可以通过运行以下命令显示支持的工具列表:
git mergetool --tool-help
您应该在可用或有效列表中看到p4merge。如果没有,请更新git。
如果p4merge被列出为可用,它在你的PATH中,你只需要设置merge.tool:
git config --global merge.tool p4merge
如果它被列为有效的,则必须定义mergetool.p4merge。除了merge.tool之外的路径:
git config --global mergetool.p4merge.path c:/Users/my-login/AppData/Local/Perforce/p4merge.exe
The above is an example path when p4merge was installed for the current user, not system-wide (does not need admin rights or UAC elevation) Although ~ 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 Even better would have been to take advantage of an environment variable (e.g. $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)
我找到了两种方法来配置“SourceGear DiffMerge”作为difftool和github Windows中的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\"'
[OR]
将以下行添加到.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\"
我用一个叫WinMerge的应用程序(http://winmerge.org/) 他们手册中的信息(http://manual.winmerge.org/CommandLine.html)
这是我通过.gitconfig从mergetool指令中使用的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的结果,并在正确的位置创建一个新的临时文件。
如果从SourceTree打开p4merge有问题,请在MyRepo下查找名为config的本地配置文件。Git并删除任何合并配置。 在我的例子中,它试图打开我刚刚卸载的Meld
我不得不在windows 7上使用msysGit删除额外的引用,不知道为什么。
git config --global merge.tool p4merge
git config --global mergetool.p4merge.cmd 'p4merge $BASE $LOCAL $REMOTE $MERGED'