其他几个人已经提到了cdiff 用于 git 并排比较,但没有人给出它的完整实现。
设置 cdiff:
git clone https://github.com/ymattw/cdiff.git
cd cdiff
ln -s `pwd`/cdiff ~/bin/cdiff
hash -r # refresh your PATH executable in bash (or 'rehash' if you use tcsh)
# or just create a new terminal
编辑 ~/.gitconfig 插入这些行:
[pager]
diff = false
show = false
[diff]
tool = cdiff
external = "cdiff -s $2 $5 #"
[difftool "cdiff"]
cmd = cdiff -s \"$LOCAL\" \"$REMOTE\"
[alias]
showw = show --ext-dif
cdiff 需要关闭寻呼机才能与 Diff 一起使用,无论如何它本质上是一个寻呼机,所以这很好。无论这些设置如何,Difftool 都可以工作。
需要显示别名,因为 git show 仅通过参数支持外部差异工具。
diff 外部命令末尾的“#”很重要。 Git 的 diff 命令将 $@(所有可用的 diff 变量)附加到 diff 命令,但我们只需要两个文件名。所以我们用 $2 和 $5 明确地调用这两个,然后将 $@ 隐藏在注释后面,否则会混淆 sdiff。导致如下错误:
fatal: <FILENAME>: no such path in the working tree
Use 'git <command> -- <path>...' to specify paths that do not exist locally.
现在产生并排比较的 Git 命令:
git diff <SHA1> <SHA2>
git difftool <SHA1> <SHA2>
git showw <SHA>
Cdiff 用法:
'SPACEBAR' - Advances the page of the current file.
'Q' - Quits current file, thus advancing you to the next file.
您现在可以通过 git diff 和 difftool 获得并行差异。如果需要,您还有用于高级用户自定义的 cdiff python 源代码。