【问题标题】:Is git difftool on binaries possible? If so, how does one configure it?二进制文件上的 git difftool 可能吗?如果是这样,如何配置它?
【发布时间】:2016-03-09 23:15:20
【问题描述】:

我一直在关注 herehere 之类的指南,了解如何在 git 中区分二进制文件 - 更具体地说是 .odt 文件和 microsoft word 文件。

他们允许我在 .odt 文件和 microsoft word 文件上 $git diff <commit> 以在终端中显示差异;但是他们的方法似乎不适用于$git difftool <commit> 处理二进制文件,例如 .odt 文件或 .docx 文件。

理想情况下,我想在外部程序(例如 git 的 kdiff3 或 vimdiff)中显示 .odt 文件或 .docx 文件的文本差异。

这可能吗?有没有人能够在 git 的外部程序中正确显示二进制文件的文本?如果是这样,有关如何为二进制文件配置 difftool 的任何建议?

【问题讨论】:

  • 我认为这取决于您为 git 配置的 difftool 的功能。 git 只会为该工具提供两个文件名。 difftool i/F的详细介绍可以通过git difftool --help

标签: git git-diff binaries git-difftool


【解决方案1】:

最近遇到了同样的问题。

来自https://git-scm.com/docs/gitattributes

A textconv, by comparison, is much more limiting. You provide a transformation of the data into a line-oriented text format, and Git uses its regular diff tools to generate the output.

简单地说,textconv 仅适用于常规 git diff,不适用于 difftool

要使 difftool 工作,请将以下内容放入 $HOME/.gitconfig:

[difftool "docx"]
    cmd = t1=`mktemp` && `pandoc -t plain $LOCAL >$t1` && t2=`mktemp` && `pandoc -t plain $REMOTE >$t2` && meld $t1 $t2 && rm -f $t1 $t2

现在你可以运行了:

$ git difftool --tool docx

上面使用 pandoc 进行 docx 到文本的转换和 meld 作为外部差异。

【讨论】:

    猜你喜欢
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    • 2022-11-12
    • 2020-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    相关资源
    最近更新 更多