如何配置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++中打开提交信息。
其他回答
参考微软的VS代码技巧和技巧。 在你的终端上运行这些命令:
Git配置全局合并。工具代码
但是首先需要将code命令添加到PATH环境变量中。
如果你想有一个选项来使用多个diff工具,添加一个别名文件。gitconfig:
[alias]
kdiff = difftool --tool kdiff3
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'输出?
添加下面的一个块可以让我在Windows和Linux开发环境中使用KDiff3。这是一个很好的一致的跨平台差异和合并工具。
Linux
[difftool "kdiff3"]
path = /usr/bin/kdiff3
trustExitCode = false
[difftool]
prompt = false
[diff]
tool = kdiff3
[mergetool "kdiff3"]
path = /usr/bin/kdiff3
trustExitCode = false
[mergetool]
keepBackup = false
[merge]
tool = kdiff3
窗户
[difftool "kdiff3"]
path = C:/Progra~1/KDiff3/kdiff3.exe
trustExitCode = false
[difftool]
prompt = false
[diff]
tool = kdiff3
[mergetool "kdiff3"]
path = C:/Progra~1/KDiff3/kdiff3.exe
trustExitCode = false
[mergetool]
keepBackup = false
[merge]
tool = kdiff3
其他人已经给出了99%的答案,但还有一个步骤被遗漏了。(我的答案将来自OS X,所以你必须相应地改变文件路径。)
对~/.gitconfig进行以下更改:
[diff]
tool = diffmerge
[difftool "diffmerge"]
cmd = /Applications/Diffmerge.app/Contents/MacOS/diffmerge $LOCAL $REMOTE
这将修复差异工具。您也可以在不编辑~/的情况下修复此问题。通过从终端输入这些命令,直接打开Gitconfig:
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "/Applications/DiffMerge.appContents/MacOS/diffmerge \$LOCAL \$REMOTE"
其他人没有提到的1%是,当使用这个时,你不能只运行git diff myfile.txt;您需要运行git difftool myfile.txt。