Git 多个diff工具
我已经将git设置为使用P4Merge作为diff工具,如前所述。因此,Git 多个diff工具,git,configuration,Git,Configuration,我已经将git设置为使用P4Merge作为diff工具,如前所述。因此,git diff将触发P4Merge 然而,有时我发现使用UNIXdiff更快、更高效(因为不涉及GUI)。如何设置git,以便轻松选择要触发的diff工具?这可能吗?例如: $ git diff # to trigger P4Merge $ git difftool # to trigger UNIX diff Mygit配置--列表: code.editor=vi merge.tool=p4merge merg
git diff
将触发P4Merge
然而,有时我发现使用UNIXdiff
更快、更高效(因为不涉及GUI)。如何设置git,以便轻松选择要触发的diff工具?这可能吗?例如:
$ git diff # to trigger P4Merge
$ git difftool # to trigger UNIX diff
Mygit配置--列表
:
code.editor=vi
merge.tool=p4merge
mergetool.extMerge.cmd=extMerge $BASE $LOCAL $REMOTE $MERGED
mergetool.extMerge.trustexitcode=false
diff.external=extDiff
mergetool.prompt=false
mergetool.keepbackup=false
mergetool.p4merge.path=/usr/local/bin/p4merge
更新:
如果您想让git difftool
调用默认的diff功能而不是外部工具,那么这个答案末尾的简单版本就可以了。但是,如果您只需要多个diff工具,我更喜欢并推荐的方法是.gitconfig文件方法,如中所述
可以将以下bash脚本设置为外部编辑工具
(即:用它替换extDiff的内容)
它不像git diif1/git diff2那么简单,但它可以工作。
编辑:有关更简单的版本,请参见底部
#!/bin/bash
# Parameters from git:
# 1 2 3 4 5 6 7
# path old-file old-hex old-mode new-file new-hex new-mode
CONTINUE=1
while [ $CONTINUE == 1 ]
do
# Present Options
echo "1. P4Merge"
echo "2. Unix diff"
echo "3. Cancel"
echo -n "Choose diff tool[1]: "
# Read in user choice
read -n 1 OPTION
# move down a line
echo ""
# if user didn't enter a choice default to 1
if [[ $OPTION == "" ]] ; then
OPTION="1"
fi
# Launch diff tool based on OPTION
case $OPTION in
1) /Applications/p4merge.app/Contents/MacOS/p4merge "$2" "$5" ; CONTINUE=0 ;;
2) diff "$2" "$5" ; CONTINUE=0 ;;
3) exit ;;
*) echo "\"$OPTION\" is not valid " ;;
esac
# This sleep has two purposes
# 1) on an invalid choice it delays the menu just a hair
# 2) keeps this script alive long enough that git will not just move onto the next file
# instantly if diffing multiple files.
sleep 1
done
没有菜单的简单版本将此函数添加到.bashrc 如果使用“git difftool”,那么它将使用默认的diff
function git {
if [[ $1 == "difftool" ]] ; then
git config --global --unset diff.external
command git diff
git config --global diff.external extDiff
else
command git "$@"
fi
}
如果Git能够以某种方式为每种设置不同,那就太好了,但如果不能,为了扩展Appak的答案,将以下内容添加到
。bashrc
可以调用text diff、opendiff(FileMerge)或P4Merge diff:
function git {
if [ $1 == "tdiff" ]
then
git config --global --unset diff.external
command git diff
elif [ $1 == "diff" ]
then
git config --global diff.external ~/bin/git-diff-opendiff
command git diff
elif [ $1 == "pdiff" ]
then
git config --global diff.external ~/bin/git-diff-p4diff
command git diff
else
command git "$@"
fi
}
只需确保您已经设置了正确的
git-diff-opendiff
和git-diff-p4diff
(它们是shell脚本)。git可以轻松地管理视觉和命令行差异。无需进行复杂的调整
git diff(默认情况下)使用unixdiff
如果您想同时使用视觉扩散工具,正确的设置方法是在~/.gitconfig
文件中使用如下部分:
[difftool "Kaleidoscope"]
cmd = ksdiff --partial-changeset --relative-path \"$MERGED\" -- \"$LOCAL\" \"$REMOTE\"
cmd=
之后的内容是特定于特定的视觉扩散应用程序的
操作git diff
将内容发送到视觉差异应用程序不是标准做法。因此,该问题寻求的答案与内置功能完全相反
有关更多详细信息,请参阅。您可以明确指出要使用哪个difftool。我的
~/.gitconfig
中有这个:
[diff]
tool = vimdiff
[difftool "winmerge"]
name = WinMerge
trustExitCode = true
cmd = "/c/Users/rkasten/Google\\ Drive/Apps/WinMerge/WinMergeU.exe" -u -e $LOCAL $REMOTE
然后我设置了以下别名:
alias gdt='git difftool'
alias gdtw='git difftool --tool=winmerge'
使用masukomi的示例,您可以将以下内容添加到gitconfig中:
[difftool "Kaleidoscope"]
cmd = ksdiff --whatevs
并使用别名gdtk='git difftool--tool=Kaleidoscope'
使用Kaleidoscope
所有这些都在Git2.7中工作。
然而,有时我发现使用UNIX diff更快、更安全
更高效(因为不涉及GUI)。如何设置git,以便轻松选择要触发的diff工具
因此,这个问题的答案应该简单地利用git区分基于控制台和基于gui的差异工具的能力,而不是依赖于编写外部命令
通过向git difftool
提供-g
选项,将从配置的变量diff.guitool
而不是diff.tool
读取要使用的diff工具
[alias]
d = difftool -g
dc = difftool
[diff]
guitool = p4merge
tool = diff
就这样。您可以使用
gitdc
或类似工具调用gui工具p4merge
,并使用gitdc
调用控制台工具(任何比此更简单的工具?:)是的,事实上,我只是想到了另一种更像你想要的方式,我编辑了我的答案above@Appak您可能需要将其改为命令git“$@”
,否则git commit-am“all done”
将不起作用上面提到的URL已损坏,请更新好吗?