当我输入git diff时,我希望看到一个并排的diff,就像用diff -y一样,或者像在kdiff3这样的交互式diff工具中显示diff。如何做到这一点呢?
当前回答
export GIT_EXTERNAL_DIFF='meld $2 $5; echo >/dev/null'
然后简单的:
git diff
其他回答
我个人非常喜欢icdiff !
如果你在Mac OS X上使用HomeBrew,只需安装icdiff即可。
为了获得正确的文件标签,加上其他很酷的功能,我在~/.gitconfig中有:
[pager]
difftool = true
[diff]
tool = icdiff
[difftool "icdiff"]
cmd = icdiff --head=5000 --highlight --line-numbers -L \"$BASE\" -L \"$REMOTE\" \"$LOCAL\" \"$REMOTE\"
我用git difftool
在这个帖子里有很多很好的答案。对于这个问题,我的解决方案是编写一个脚本。
将其命名为“git-scriptname”(并使其可执行并将其放在您的PATH中,就像任何脚本一样),您可以像正常的git命令一样通过运行调用它
$ git scriptname
实际的功能在最后一行。来源如下:
#!/usr/bin/env zsh
#
# Show a side-by-side diff of a particular file how it currently exists between:
# * the file system
# * in HEAD (latest committed changes)
function usage() {
cat <<-HERE
USAGE
$(basename $1) <file>
Show a side-by-side diff of a particular file between the current versions:
* on the file system (latest edited changes)
* in HEAD (latest committed changes)
HERE
}
if [[ $# = 0 ]]; then
usage $0
exit
fi
file=$1
diff -y =(git show HEAD:$file) $file | pygmentize -g | less -R
我最近实现了一个这样做的工具:https://github.com/banga/git-split-diffs
下面是如何使用它:
npm install -g git-split-diffs
git config --global core.pager "git-split-diffs --color | less -RFX"
这是它在终端中的外观(使用默认主题):
如您所见,它还支持语法高亮显示和行中更改的单词高亮显示
如果你想在不涉及GitHub的情况下在浏览器中看到并排的差异,你可能会喜欢git webdiff,它是git diff的替代品:
$ pip install webdiff
$ git webdiff
与传统的GUI差异工具(如tkdiff)相比,这提供了许多优势,因为它可以为您提供语法高亮显示和显示图像差异。
点击这里阅读更多信息。
这里有一个方法。如果管道通过less, xterm宽度设置为80,这不是很热。但是如果继续执行命令,例如COLS=210,则可以使用扩展的xterm。
gitdiff()
{
local width=${COLS:-$(tput cols)}
GIT_EXTERNAL_DIFF="diff -yW$width \$2 \$5; echo >/dev/null" git diff "$@"
}
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别