Integrate git diffs with word docx files

Ramón Casero edited this page Jul 10, 2016 · 5 revisions

See diffs of .docx files with git wdiff file.docx.

This section was inspired by Martin Fenner's "Using Microsoft Word with git".

To configure git diff:

  1. Install pandoc.

  2. Tell git how to handle diffs of .docx files.

    1. Create or edit file ~/.gitconfig (linux, Mac) or "c:\Documents and Settings\user.gitconfig" (Windows) to add

       [diff "pandoc"]
         textconv=pandoc --to=markdown
         prompt = false
         wdiff = diff --word-diff=color --unified=1
    2. In your paper directory, create or edit file .gitattributes (linux, Windows and Mac) to add

       *.docx diff=pandoc
    3. You can commit .gitattributes so that it stays with your paper for use in other computers, but you'll need to edit ~/.gitconfig in every new computer you want to use.

Now you can see a pretty coloured diff with the changes you have made to your .docx file since the last commit

git wdiff file.docx

To see all changes over time

git log -p --word-diff=color file.docx

Track changes in Word (.docx) documents getting a diff with the commit.

Automatically when running git commit.

This is only going to work from linux/Mac or Windows running git from a bash shell.

  1. Install pandoc. Pandoc is a program to convert between different file formats. It's going to allow us to convert Word files (.docx) to Markdown (.md).

  2. Set up git hooks to enable automatic generation and tracking of Markdown copies of .docx files.

    Copy these hook files to your git project's .git/hooks directory and rename them, or soft-link to them with ln -s, and make them executable (chmod u+x *.sh):

    Now every time you run git commit, the pre-commit hook will automatically run before you see the window to enter the log message. The hook is a script that makes a copy in Markdown format (.md) of every .docx file you are committing. The post-commit hook then amends the commit adding the .md files.

Manually by creating a Markdown copy of the .docx file.

This works in linux, Mac and Windows.

  1. Install pandoc.

  2. Edit your Word document as needed.

  3. Run pandoc from the linux or Windows command line. This will create a Markdown version of your file (without Figures, but with equations in latex format)

     pandoc -s file.docx -t markdown -o
  4. Update the ChangeLog

  5. Commit both files with git

     git add file.docx
     git commit
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.