Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 478
Jack Avatar asked Nov 01 '25 16:11

Jack


1 Answers

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.

like image 64
ten0s Avatar answered Nov 03 '25 08:11

ten0s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!