So, you would like to check for modifications on a Word document that is version controlled with Git, right? Want to see it in a nice and convenient way like you can see on this screenshot? Then read on!
The Simple Way
Let's create an empty Git repository and add a simple Word document (I'm using Git from Cygwin here):rlegendi@WOLFGANG /c/worddiff $ git init Initialized empty Git repository in C:/worddiff/.git/ rlegendi@WOLFGANG /c/worddiff (master) $ git add test.docx rlegendi@WOLFGANG /c/worddiff (master) $ git commit -m "Added draft Word document" [master (root-commit) cbfafeb] Added draft Word document 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.docx
After editing the file, the good thing is that you can see the difference in pure diff format by using the default git diff command:
rlegendi@WOLFGANG /c/worddiff (master) $ git diff diff --git a/test.docx b/test.docx index f50e2d6..c04f096 100644 --- a/test.docx +++ b/test.docx @@ -1,3 +1,4 @@ Some Title Heading And some text... +In his house at R'lyeh, dead Cthulhu waits dreaming.
Now here comes the interesting part!
Configure Visual Tools
In this example, we are going to link TortoiseSVN's tools to Git. They are nice, working perfectly, nevertheless they are tested and verified in various environments.You don't have to install the client, all these scripts are available online, but if you have already have it installed like me you don't need anything just link it to directly to Git (all the scripts can be found in the TortoiseSVN\Diff-Scripts directory).In the following example, we will define how to diff word docs by using the diff-doc.js script. Merging them or extending these functionalities to *.pptx, *. odt, *. nb, *.sxw, *. xls or *.dll files is trivial based on this example.
Basically, you don't need anything just open up the .gitconfig file (either the global one in your home or the one in the test git repository's .git folder) and add the following entry to it:
[diff] tool = wdiff [difftool "wdiff"] cmd="wscript.exe \"c:\\Program Files\\TortoiseSVN\\Diff-Scripts\\diff-doc.js\" \"$LOCAL\" \"`pwd`/$REMOTE\""
This is a new difftool definition called wdiff. Note two small tricks here. The first thing is that we execute the script with wscript.exe. The second thing is the `pwd/` entry before the $REMOTE reference: that's because Git passes only the relative path to the specified file and the diff-doc.js script requires an absolute path. By the way, the script is a simple JavaScript file with some ActiveX-magic, but I suppose you're here because you are using Git from Windows. Otherwise this trick might still work under Linux through Wine if you are facing the problem how to compare Word documents :-)) (It is just an assumption, but it would be nice to hear any experience from you guys!).
That two line of configuration is enough. You can try diffing any Word document with your cool new feature by calling specifically the wdiff tool:
rlegendi@WOLFGANG /c/worddiff (master) $ git difftool -t wdiff test.docx
And there you have this nice comparison view! You see a short summary of modifications on the upper left corner, see detailed logs on the left, a nicely decorated diff in the middle, the original file the diff in the middle, the previous version of the document upper right corner, and the current version in the lower right corner.
Hope that helps you guys! Have fun!
A Few Remaining Questions
- Does TortoiseGit have the same functionailty by default?
- Is it possible to hack this together under Linux?

Thanks for this post, I can confirm that this works in Tortoise-Git, as mentioned in my blog post below:
ReplyDeletehttp://berryware.wordpress.com/2013/01/21/nice-surprise-tortoise-git-word-document-diff/
I wouldn't have been sure that it was Git if it wasn't for your post confirming this!
Hi Kevin,
ReplyDeleteThx for the update and the confirmation!
Actually, I believe these scripts are additions from the Tortoise-xxx software family (I saw it working a few years ago in TortoiseSVN).