How can I add a different Git diff tool for 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)?

  • How to migrate large bzr project with many branches to git and filter history
  • How to conveniently sync a file between two git repositories
  • Git How to commit after closing editor?
  • Track files locally, but never allow them to be pushed to the remote repository
  • Cannot open FETCH_HEAD after renaming a branch
  • Error deploying to Azure through git (bitbucket hosted git repo)
  • I’ve configured git to use meld like this:

    1. Create a script called git-meld:

      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.

  • Is there a way to back to the lastest branch?
  • Is there a good (visual) Git tool for Mac OS X or Windows?
  • Git tries to commit submodules files into parent project
  • git svn clone results in empty directory
  • Android studio shelved changes disappeared, not even in the .idea/shelf directory
  • git set-upstream-to VR track
  • 2 Solutions collect form web for “How can I add a different Git diff tool for PDF?”

    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…

    You can use git difftool (man git difftool).

    $ git difftool #opens in the tool defined in config: git config --get diff.tool
    $ git difftool --tool meld # Opens in meld, regardless of what you configured.
    $ git difftool --tool diffpdf # Opens in diffpdf. 
    Git Baby is a git and github fan, let's start git clone.