Use Git for your PDF and Word .doc files!

Afik Cohen
Aug 5, 2014 · 2 min read

Sure, you’d love to do this, who wouldn’t? Word and PDF are awful file formats, but they’re still widespread and if you’re housing your important documents in them, and you’re like me, then you want them version controlled. Git can handle any binary file of course, but where’s the fun in seeing this?

$ git diff 
diff --git a/chapter1.doc b/chapter1.doc
index 88839c4..4afcb7c 100644
Binary files a/chapter1.doc and b/chapter1.doc differ

Enter .gitattributes.

Step by Step setup

Stick the following line in a .gitattributes file in your repo:

*.doc diff=word

I’ll let them explain:

This tells Git that any file that matches this pattern (.doc) should use the “word” filter when you try to view a diff that contains changes. What is the “word” filter? You have to set it up. Here you’ll configure Git to use the catdoc program, which was written specifically for extracting text from a binary MS Word documents … to convert Word documents into readable text files, which it will then diff properly:

$ git config diff.word.textconv textract

I deleted the stuff about catdoc because that project’s dead. Let’s use the lovely library I recently discovered instead.

$ pip install textract

For it to work with .doc files, we’ll need antiword installed too:

$ brew install antiword

Then let’s run a git diff:


Originally published at on August 5, 2014.

Afik Cohen

Written by