Change history for a document in a git repository

In Writer and Calc, if a document has been edited without change tracking enabled, but I have both the old and the new version, I can compare the document as follows:

  • Open the newest version.
  • From the menu, choose Edit > Track Changes > Compare Document… and select the previous version.
  • To compare more than two versions, repeat the previous step for each old version, going from newest to oldest.

This will give me a document with all changes over the versions highlighted.

Now suppose I have a document tracked in a git repository: every time someone makes changes to the document, they commit them. I am aware one could save the document in FOD* format, resulting in a flat-file XML document which can be viewed with the usual diff tools, but that does not work well with all types of content (think spreadsheets or text documents with tables or images).

I could extract both versions from git and use Compare Document as above, which would give me a version-tracked document, but that requires a lot of manual steps.

Is there a convenient way to compare two different versions of a document tracked in a git repository, with a Compare Document-like UX?

This comment only to be notified automatically of answers

Presently, I don’t commit my “long-term” documents to git because git sees the zipped .odt as an unknown binary. The .fodt trick won’t give me the visibility I’m looking for. There are two aspects in change tracking:

  • following bare content evolution
  • tracking formatting adjustments

Both are intermixed in XML and a “dumb” tool like diff will not separate levels because it can’t make any difference between markup (styling) and wording. As an editor, I need to consider these abstract levels at different times in the process of reviewing copy.

To illustrate the difficulty, consider an image where a single pixel was modified. I don’t care for the pixel itself, what is important to me is the fact the the image, as a whole, is no longer the same.

@ajlittoz presenting the changes is something LO has already solved, as far as I’m concerned—Track Changes gives me about the user experience I am looking for. My question was how to get a Track Changes-like UX with a git versioned document.

Not a fully automated approach yet, but here is how to do it in a few steps:

  • From the command line, run:

    git show rev:somedoc.odt > /tmp/somedoc@rev.odt

(replace rev with the branch, tag or revision for the previous version)

  • Open the current version in LibreOffice.

  • From the menu, choose Edit > Track Changes > Compare Document… and choose /tmp/somedoc@rev.odt.

Now you have the document with all changes made from rev to HEAD highlighted. Tested with Writer, should work with all LibreOffice applications which do change tracking. Drawbacks of this solution:

  • No blame—the person doing the comparison will appear as the author of all changes.
  • No version-by-version comparison—you will get a diff of new vs. old. (You might be able to do this in multiple stages, at least as long as the version history is linear.)

The same would work for comparing two arbitrary versions: simply extract the “current” version in the same manner as shown above and open that instead of the file in the repo.

This could probably be turned into a simple macro.