NirViaje / nirviaje.github.io

https://nirviaje.github.io/
16 stars 4 forks source link

git diff with binary #78

Open NirViaje opened 2 years ago

NirViaje commented 2 years ago

https://tante.cc/2010/06/23/managing-zip-based-file-formats-in-git/

Open your ~/.gitconfig file (create if not existing already) and add the following stanza:

[diff "zip"]
textconv = unzip -c -a

What it does is using “unzip -c -a FILENAME” to convert your zipfile into ASCII text (unzip -c unzips to STDOUT). Next thing is to create/modify the file REPOSITORY/.gitattributes and add the following

*.pptx diff=zip

https://tante.cc/2009/03/24/versioning-pdf-files-with-git/

git diff
.

If you have a recent git version (>1.6) you just have to do three things:

Since git needs the contents to diff on stdout you have to write a short wrapper for pdftotext. Call it “pdf2txt”, put it in /usr/local/bin or if you have it in ~/bin. It contains:
#!/bin/bash
pdftotext $1 -
to your
~/.gitconfig
file add the paragraph

[diff "pdf"]
    textconv = pdf2txt
This tells git that if you select the diff mechanism “pdf” to use the command “pdf2txt” (the wrapper we created) to convert the given data object to text.

In your repository edit the file
.gitattributes
and add the line

*.pdf diff=pdf
It tells git to use the “pdf” diff mechanism (the one we set up in step 2) for any file that matches the description “*.pdf” (as in “any .pdf file”, you could setup different textual representation tools for differently named pdfs if you wanted to).

Now git will show you proper text-diffs for your pdf files when using git diff or when looking at the different commits.