如何配置Git以使用不同的工具来区分.gitconfig文件?
我在我的.gitconfig中有这个:
[diff]
tool = git-chdiff #also tried /bin/git-chdiff
它不起作用;它只是打开常规命令行差异。当我这样做
export GIT_EXTERNAL_DIFF=git-chdiff
然后git diff将打开外部差异工具(所以我知道外部差异工具脚本工作良好)。我对diff工具的.gitconfig配置有问题吗?
如何配置Git以使用不同的工具来区分.gitconfig文件?
我在我的.gitconfig中有这个:
[diff]
tool = git-chdiff #also tried /bin/git-chdiff
它不起作用;它只是打开常规命令行差异。当我这样做
export GIT_EXTERNAL_DIFF=git-chdiff
然后git diff将打开外部差异工具(所以我知道外部差异工具脚本工作良好)。我对diff工具的.gitconfig配置有问题吗?
当前回答
在Windows中,我们需要运行git difftool——tool-help命令来查看各种选项,例如:
'git difftool --tool=<tool>' may be set to one of the following:
vimdiff
vimdiff2
vimdiff3
The following tools are valid, but not currently available:
araxis
bc
bc3
codecompare
deltawalker
diffmerge
diffuse
ecmerge
emerge
examdiff
gvimdiff
gvimdiff2
gvimdiff3
kdiff3
kompare
meld
opendiff
p4merge
tkdiff
winmerge
xxdiff
Some of the tools listed above only work in a windowed
environment. If run in a terminal-only session, they will fail.
我们可以添加它们中的任何一个(例如,WinMerge)
git difftool --tool=winmerge
将notepad++配置为在提交前查看文件:
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
使用git commit将在notepad++中打开提交信息。
其他回答
Git提供了一系列预配置的“开箱即用”的difftools (kdiff3、kompare、tkdiff、meld、xxdiff、emerge、vimdiff、gvimdiff、ecmerge、diffuse、opendiff、p4merge和araxis),还允许您指定自己的difftools。要使用一个预先配置的difftools(例如,“vimdiff”),您可以在~/.gitconfig中添加以下行:
[diff]
tool = vimdiff
现在,您将能够运行“git difftool”并使用您选择的工具。
另一方面,指定你自己的difftool需要更多的工作,看看我如何用我喜欢的diff工具/查看器查看'git diff'输出?
这是我的~/的一部分。gitconfig,我配置差异和合并工具。我喜欢SourceGear的diffmerge。(事实上,我非常非常喜欢它)。
[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = "diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$(if test -f \"$BASE\"; then echo \"$BASE\"; else echo \"$LOCAL\"; fi)\" \"$REMOTE\""
trustExitCode = false
[diff]
tool = diffmerge
[difftool "diffmerge"]
cmd = diffmerge \"$LOCAL\" \"$REMOTE\"
你看,你在[difftool "diffmerge"]行中定义了一个名为"diffmerge"的工具。然后我在[diff] tool =部分设置工具“diffmerge”为默认值。
很明显,我的路径中有diffmerge命令。否则,我需要给出可执行文件的完整路径。
在Windows中,我们需要运行git difftool——tool-help命令来查看各种选项,例如:
'git difftool --tool=<tool>' may be set to one of the following:
vimdiff
vimdiff2
vimdiff3
The following tools are valid, but not currently available:
araxis
bc
bc3
codecompare
deltawalker
diffmerge
diffuse
ecmerge
emerge
examdiff
gvimdiff
gvimdiff2
gvimdiff3
kdiff3
kompare
meld
opendiff
p4merge
tkdiff
winmerge
xxdiff
Some of the tools listed above only work in a windowed
environment. If run in a terminal-only session, they will fail.
我们可以添加它们中的任何一个(例如,WinMerge)
git difftool --tool=winmerge
将notepad++配置为在提交前查看文件:
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
使用git commit将在notepad++中打开提交信息。
在前面的回答中,几乎所有的解决方案都不能在Git版本2中使用
我的:Git版本= 2.28.0
difftool的解决方案:git配置——global diff.tool vimdiff
有了它,你就可以毫无问题地使用它了。
参考微软的VS代码技巧和技巧。 在你的终端上运行这些命令:
Git配置全局合并。工具代码
但是首先需要将code命令添加到PATH环境变量中。