git difftool可以用于二进制文件吗?如果是这样,如何配置它? [英] Is git difftool on binaries possible? If so, how does one configure it?

查看:227
本文介绍了git difftool可以用于二进制文件吗?如果是这样,如何配置它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在遵循此处

I've been following guides like these here and here on how to diff binaries in git - more specifically .odt files and microsoft word files.

他们允许我在.odt文件和Microsoft Word文件上使用$git diff <commit>在终端中显示差异;但是,它们的方法似乎不适用于二进制文件(例如.odt文件或.docx文件)上的$git difftool <commit>.

They have allowed me to $git diff <commit> on .odt files and microsoft word files to display the difference in the terminal; however their methods don't seem to work with $git difftool <commit> on binary files, such as .odt files or .docx files.

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

Ideally I would like to display the text diff of .odt files or .docx files in an external program such as kdiff3 or vimdiff from git.

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

Is this possible? Has anyone been able to correctly display the text of binary files in an external program from git? If so, any advice on how to configure difftool for binaries?

推荐答案

最近遇到了同样的问题.

Recently faced the same problem.

来自 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 .

Simply put, textconv only works for the regular git diff, not for difftool.

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

To make difftool work, put the below into $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转换为文本,并使用 melt 作为外部差异.

The above uses pandoc for docx to text conversion and meld as an external diff.

这篇关于git difftool可以用于二进制文件吗?如果是这样,如何配置它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆