Tuesday, March 31, 2015

Using git with Word

I like git, and I like to use it with most of my projects. I use LaTeX for documents, but sometimes I need to use Word. (Apparently ISME J does not accept submissions in TeX. It only accepts Word, rtf, and, unbelievably, plain txt.)

Word uses a binary format, so git diff normally displays nothing useful. Martin Fenner posted an incredibly useful blog post that solves this whole problem for me.

I'm on OSX. First, I got pandoc, a tool that turns Word files into simpler text formats that can be more easily piped into diff.

Second, I needed to add some lines to the .gitconfig file in my home directory:

[diff "pandoc"]
  textconv=pandoc --to=markdown
  prompt = false
[alias]
  wdiff = diff --word-diff=color --unified=1

Third, in the git repo, I needed to add a new file .gitattributes with contents

*.docx diff=pandoc

Et voila! git diff works just like I would hope.

No comments:

Post a Comment