Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

git diff - Is git difftool on binaries possible? If so, how does one configure it?

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.

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.

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Recently faced the same problem.

From 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.

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

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

Now you can run:

$ git difftool --tool docx

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...