当我输入git diff时,我希望看到一个并排的diff,就像用diff -y一样,或者像在kdiff3这样的交互式diff工具中显示diff。如何做到这一点呢?


当前回答

打开Intellij IDEA,在“版本控制”工具窗口中选择单个或多个提交,浏览更改的文件,然后双击它们,并排检查每个文件的更改。

使用捆绑的命令行启动器,您可以在任何地方使用简单的IDEA some/path启动IDEA

其他回答

如果你想在不涉及GitHub的情况下在浏览器中看到并排的差异,你可能会喜欢git webdiff,它是git diff的替代品:

$ pip install webdiff
$ git webdiff

与传统的GUI差异工具(如tkdiff)相比,这提供了许多优势,因为它可以为您提供语法高亮显示和显示图像差异。

点击这里阅读更多信息。

伊迪夫

这个工具以前称为cdiff,可以并排显示、增量显示和彩色显示差异。

而不是做git diff,做:

ydiff -s -w0

这将为每个有差异的文件以并排显示模式启动ydiff。

安装:

python3 -m pip install --user ydiff

-or-

brew install ydiff

对于git日志,您可以使用:

ydiff -ls -w0

-w0自动检测终端宽度。有关详细信息和演示,请参阅ydiff GitHub存储库页面。

在Git 2.18.0, ydiff 1.1中测试。

我个人非常喜欢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

这可能是一个有点有限的解决方案,但在没有外部工具的情况下使用系统的diff命令完成工作:

diff -y  <(git show from-rev:the/file/path) <(git show to-rev:the/file/path)

仅过滤更改行使用——suppress-common-lines(如果您的diff支持该选项)。 在这种情况下,没有颜色,只有通常的不同标记 可以调整列宽度-width=term-width;在Bash中可以获取宽度为$COLUMNS或tput cols。

为了更方便,这也可以被包装到一个helper git-script中,例如,这样使用:

git diffy the/file/path --from rev1 --to rev2

在这个帖子里有很多很好的答案。对于这个问题,我的解决方案是编写一个脚本。

将其命名为“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