31

LibreOffice saves into files that are zip files. Zip files are generally suboptimal to use with Git: A small change in the document can change most of the zip-file, thus making it impossible for Git to reuse parts which results in the Git repository grows with the full size of the zip file instead of just the few changes.

Is there a way in which I can tell LibreOffice to save in a Git friendly format?

E.g. by saving as a zip file with no compression (ala .tar) or simply saving the document as a dir containing the same files as the unpacked zip file would result in.

3 Answers 3

40

Is there a way in which I can tell LibreOffice to save in a Git friendly format?

You can save your files as flat XML (fodt) instead of odt:

If a document is saved as .fodt file it keeps the same data the .odt file would contain. Only that this time the data is represented as human-readable text (which makes the work much easier for the version control system) and not compressed. So saving a document as flat XML makes it possible to keep server space requirements and network load low at the relatively low cost of wasting a few kilobytes on the local hard disks.

Source LibreOffice and Version control


Further Reading

3
  • The option discussed in the last link (to add newlines) appears to have been dropped in LO -- I can't find it in the Load/Save settings.
    – retorquere
    Commented Apr 7, 2018 at 7:55
  • @retorquere Indeed. Looks like it was removed. Answer updated to remove that link.
    – DavidPostill
    Commented Apr 7, 2018 at 15:17
  • This answer is good, but not great. That said, I'm not sure there's a great answer. Using fodt instead of odt is great if you're using a single-user linear strategy, just tracking file changes. But this is very painful if you try to use it in a multi-user or branching environment, because merging two edits simply doesn't work well, due to the way libre office does formatting. (Formats are declared at the beginning and numbered in order and nums references, and two people adding paragraphs will have different number schemes, making merge conflicts of doom.)
    – lilHar
    Commented Jul 23, 2023 at 6:23
3

ReZipDoc is a tool that uses git clean (and optionally smudge) filters for ZIP based files stored in git (ODT is basically a ZIP file).

IT simply re-zips the ODT without compression, and tells git to treat ODTs as text files. Apart from included images, the data within an ODT, and thus the files within the ODT ZIP, are mostly text based. Thus this approach works nicely with git delta compression. LibreOffice its-self has no problem reading uncompressed ODT files, and thus there is no downside to this approach, apart form having to setup ReZipDoc in the local repositories of all collaborators.

In theory, the final size of the git repo should be more or less the same as if using FODT, provided LibreOffices formats the text parts consistently in both cases.

1

I have written a bash script that enhances Libreoffice docs into git friendly format - see https://github.com/timwiel/libreoffice2git

1
  • 1
    Can you compare how the space performance differs from using .fodt?
    – Ole Tange
    Commented May 20, 2020 at 12:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .