Binary files and git repositories can be a pain, especially when looking at the
git diff output. Here are two helpful things to do with git to make working
with .pdfs less painful.
The standard output from
git diff when a tracked
diff --git a/dissertation.pdf b/dissertation.pdf index 2a9ec08..d3aaa79 100644 Binary files a/dissertation.pdf and b/dissertation.pdf differ
Not the most helpful output. The two things I have found to be helpful are
git difftoolto call
- Have the differences in the
pdfinforeturned when calling
Note, I’m writing this on a Debian machine. Set up for other Linux distributions, Winblows and Mac may differ.
Setting up git to use
diffpdf is simple. In either you project or global config
file add the following lines
[difftool "diffpdf"] cmd = diffpdf \"$LOCAL\" \"$REMOTE\"
From the command line
git difftool --no-prompt --tool=diffpdf dissertation.pdf
will open the
diffpdf gui and show the differences, changes, in the
dissertation.pdf file. I find this to be the most helpful when comparing
different versions of the
git difftool --no-prompt --tool=diffpdf version-0.9.1:dissertation.pdf dissertation.pdf
Now, from time to time, I know that the
show the changes in the pdf metadata do the following.
Add, or add to,
.gitattributes file. Setting one up for all your repos is done
by adding the following to you global git config file
git config --global core.attributesfile ~/.gitattributes echo "*.pdf diff=diffpdfinfo" >> ~/.gitattributes
If you only want this to work in one particular repository you need only create
.gitattributes file in the project root directory.
We need to write the
diffpdfinfo script and save it somewhere in your
#!/bin/bash pdfinfo $1 > .localpdfmetadata pdfinfo $2 > .remotepdfmetadata diff .localpdfmetadata .remotepdfmetadata
Remember to made the script executable via
git diff has meaningful output for the
diffpdf tool telling me the
two files are the same. However,
git diff tells me they are different,
specifically in that the creation date and modification dates have change.
$ git diff diff --git a/dissertation.pdf b/dissertation.pdf index 2a9ec08..edd66d8 100644 --- a/dissertation.pdf +++ b/dissertation.pdf @@ -4,8 +4,8 @@ Keywords: Author: Creator: LaTeX with hyperref package Producer: pdfTeX-1.40.15 -CreationDate: Wed Mar 29 14:55:27 2017 -ModDate: Wed Mar 29 14:55:27 2017 +CreationDate: Mon Apr 3 00:41:05 2017 +ModDate: Mon Apr 3 00:41:05 2017 Tagged: no UserProperties: no Suspects: no
Diffing a draft version to the current version there should be some changes in the metadata. The creation and modification dates have changed, but so has the number of pages and the file size.