Is git difftool on binaries possible? If so, how does one configure it?
Asked Answered
I

1

4

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?

Interval answered 4/12, 2015 at 22:1 Comment(1)
I think this depends on the capability of difftool you configured for git. git will only provides two file names for the tool. You can find details introduction about difftool i/F by git difftool --helpAchromatin
V
3

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.

Veratrine answered 18/4, 2020 at 13:15 Comment(1)
works on Windows (I was skeptical, but to my surprise a blind copy-paste actually worked)! Here's what I used for my Excel file diffing problem, in conjunction with Beyond Compare: [difftool "xlsx"] cmd = t1=`mktemp` && `python C:/Users/myUser/Miniconda3/Scripts/git-xlsx-textconv.py $LOCAL >$t1` && t2=`mktemp` && `python C:/Users/myUser/Miniconda3/Scripts/git-xlsx-textconv.py $REMOTE >$t2` && "C:/Program\\ Files/Beyond\\ Compare\\ 4/BCompare.exe $t1 $t2" && rm -f $t1 $t2Probe

© 2022 - 2024 — McMap. All rights reserved.