如何配置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配置有问题吗?
当前回答
另一种方法(从命令行):
git config --global diff.tool tkdiff
git config --global merge.tool tkdiff
git config --global --add difftool.prompt false
前两行将difftool和mergetool设置为tkdiff—根据您的首选项进行更改。第三行禁用了恼人的提示,因此无论何时点击git difftool,它都会自动启动difftool。
其他回答
添加下面的一个块可以让我在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。
在前面的回答中,几乎所有的解决方案都不能在Git版本2中使用
我的:Git版本= 2.28.0
difftool的解决方案:git配置——global diff.tool vimdiff
有了它,你就可以毫无问题地使用它了。
在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 config --global diff.tool tkdiff
git config --global merge.tool tkdiff
git config --global --add difftool.prompt false
前两行将difftool和mergetool设置为tkdiff—根据您的首选项进行更改。第三行禁用了恼人的提示,因此无论何时点击git difftool,它都会自动启动difftool。