Lately I’ve been looking at different ways to do version control with office documents. I’ve been interested in this because I write stories and it’s nice to be able to see my work as I go along.

I’ve found two different way to do this.

Internal

The first method is using OpenOffice/LibreOffice’s own internal version control system. It’s pretty simple. You just enable the recording of changes under:

Menu > Edit > Changes > Record Changes

You can adjust how it saves the changes, and how it displays them.

Once you’ve done some changes to a document, you’ll want to use the Accept or Reject Changes window to pick the changes you want to keep (probably all) and to make a checkpoint.

You can read more about it here.

Git

Woah! Git? I thought this article was about document editing, not… code.

Well, text is text. But the issue with git is it uses text files, and Open/LibreOffice is zip file of documents.

If you use it straight, you’ll just see this when you commit:

Binary files "a/overview.ods" and "b/overview.ods" differ

Well, that’s not very helpful on what changed.

Instead, let’s use some text processors to can easily show us what’s been changed.

First, install odt2txt and xmllint, as shown below:

apt-get install odt2txt xmllint
dnf install odt2txt xmllint
pacman -Sy odt2txt xmllint

Then put this program in your path:

#!/usr/bin/env sh
# place this file to ~/bin/odf2prettytxt and have ~/bin in $PATH 
set -o errexit
odt2txt --raw "$@" | xmllint --format -

The program parses the document into text. We just need to tell git to use this new program for office docs:

git config --global diff.odf.textconv "odf2prettytxt"

And in our .gitattributes we add this so it knows what types of files it has:

.ods diff=odf
.odt diff=odf
.odp diff=odf

And finally add this to .gitignore so it won’t show up in the commits:

.~lock.*

That’s it. Now we can record the changes as we write the story, making it much easier to go back and get back that really cool passage.

References: