Join GitHub today
Integrate git diffs with word docx files
See diffs of .docx files with git
This section was inspired by Martin Fenner's "Using Microsoft Word with git".
To configure git diff:
Tell git how to handle diffs of .docx files.
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 [alias] wdiff = diff --word-diff=color --unified=1
In your paper directory, create or edit file .gitattributes (linux, Windows and Mac) to add
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
This is only going to work from linux/Mac or Windows running git from a bash shell.
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).
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/hooksdirectory and rename them, or soft-link to them with
ln -s, and make them executable (
chmod u+x *.sh):
- pre-commit-git-diff-docx.sh -> .git/hooks/pre-commit
- post-commit-git-diff-docx.sh -> .git/hooks/post-commit
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.
Edit your Word document as needed.
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 file.md
Update the ChangeLog
Commit both files with git
git add file.docx file.md git commit