Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a different Git diff tool for PDF?

Tags:

git

pdf

I currently use meld as a Git diff tool. This works great, but I also have some PDF files under version control. Always when I make git diff I get ugly messages that inform me, that meld can't compare those binary files.

Today, I've found diffpdf which works great. But how can I configure git to use diffpdf for PDF (and only for them)?

I've configured git to use meld like this:

  1. Create a script called git-meld:

    #!/bin/bash
    meld "$2" "$5"
    
  2. Make it executable: chmod +x git-meld

  3. Add it to my config file: git config --global diff.external git-meld

But obviously I can't simply adapt this way to use both, diffpdf and meld.

like image 888
Martin Thoma Avatar asked Oct 28 '13 09:10

Martin Thoma


People also ask

Does diff work on PDF?

6 Answers. You can use DiffPDF for this. From the description: DiffPDF is used to compare two PDF files.

Can git track PDF files?

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

How do I get git diff?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.


1 Answers

You need to look at the gitattributes manual page. Basically, you create an external diff driver that specifies a custom command to use for comparing a specific type of file (this goes in ~/.gitconfig or ${PROJECT}/.git/config):

[diff "pdfdiff"]
    command = diffpdf

Then you specify that certain types of files use that diff driver (in ${PROJECT}/.gitattributes or {PROJECT}/some/subdir/.gitattributes):

*.pdf diff=pdfdiff

Then everything except pdf files will use your normal git diff defaults, but pdf files will call diffpdf when you git diff them...

like image 165
twalberg Avatar answered Oct 25 '22 16:10

twalberg