当我键入gitdiff时,我想用我选择的可视化diff工具(Windows上的SourceGear“diffmerge”)查看输出。如何配置git以执行此操作?
当前回答
尝试此解决方案:
$ meld my_project_using_git
Meld了解Git,并提供最近更改的导航。
其他回答
Windows/MSYS Git解决方案
看完答案后,我发现了一种更简单的方法,只需要更改一个文件。
使用参数2和5创建一个批处理文件来调用diff程序。此文件必须位于您路径中的某个位置。(如果您不知道它在哪里,请将其放在C:\windows中。)调用它,例如,“gitdiff.bat”。我的是:@回声消失REM这是gitdiff.bat“C:\Program Files\WinMerge\WinMergeU.exe”%2%5将环境变量设置为指向批处理文件。例如:GIT_EXTERNAL_DIFF=gitdiff.bat。或通过PowerShell键入GIT-config--globaldiff.EXTERNAL gitdiff.bat。重要的是不要使用引号或指定任何路径信息,否则将无法工作。这就是为什么gitdiff.bat必须在您的路径中。
现在,当您键入“gitdiff”时,它将调用外部diff查看器。
这在Windows 7上适用。不需要中间sh脚本
.gitconfig的内容:
[diff]
tool = kdiff3
[difftool]
prompt = false
[difftool "kdiff3"]
path = C:/Program Files (x86)/KDiff3/kdiff3.exe
cmd = "$LOCAL" "$REMOTE"
对以前的伟大答案的简短总结:
git difftool --tool-help
git config --global diff.tool <chosen tool>
git config --global --add difftool.prompt false
然后通过键入(也可以选择指定文件名)使用它:
git difftool
我在Ubuntu上使用Kompare:
sudo apt-get install kompare
要比较两个分支:
git difftool -t kompare <my_branch> master
我在这里尝试了一些新奇的东西(使用tkdiff),但没有任何效果。所以我写了下面的脚本,tkgitdiff。它做了我需要它做的事。
$ cat tkgitdiff
#!/bin/sh
#
# tkdiff for git.
# Gives you the diff between HEAD and the current state of your file.
#
newfile=$1
git diff HEAD -- $newfile > /tmp/patch.dat
cp $newfile /tmp
savedPWD=$PWD
cd /tmp
patch -R $newfile < patch.dat
cd $savedPWD
tkdiff /tmp/$newfile $newfile