17

The idea is that I want to share and track documents over git

I thought about using Text Documents (markdown docs that look like docx,odt in functionality) that can be edited with any text editor (not binary). Where to find something like this?

any better solution?

MhdSyrwan
  • 1,613
  • 3
  • 19
  • 26
  • @LazyBadger: that's not 100% true. ODT is zipped XML... – eckes Jan 10 '12 at 06:40
  • @eckes: When zip became text? Did I miss something? – Lazy Badger Jan 10 '12 at 10:39
  • 2
    is there any way to zip/unzip those files when using git commands ? my problem is that git sees those files as binary (because they're zipped) when conflict happens ,i can't resolve it any way !! :( – MhdSyrwan Jan 10 '12 at 15:41
  • I also would be happy to see a git hook or workaround to make git recognize archives (and to be able to work with them as directories). – n611x007 Nov 18 '12 at 15:29

4 Answers4

30

LaTeX is perfect for combining it for git. But if you cannot afford yourself the time to "translate" all to LaTeX, I think a great option that fits your needs is using LibreOffice and saving files in .fodt format (Open Document Text - Flat XML). These files are uncompressed XML, so you can use all the power of git as you can see addition and changes to the document line per line.

This will make merging an easy task. Even binaries (e.g. when you include an image) will be embedded in the document and shown as text. Of course you cannot manipulate them from there but you can remove the whole tag or edit attributes with the simplest text editor.

froskos
  • 494
  • 5
  • 10
  • This actually answers the question best. Recommending alternatives (like LaTex) is fine, but this shows an easy workaround that does not require installing additional software (for diffs) and thus also works on repository hosting platforms like GitHub or GitLab. – rugk Feb 10 '20 at 17:29
  • Sadly, using this method, the file size increases a lot. One of my files, from 10 MB to 200 MB. – dmcontador Jan 25 '21 at 10:11
29

There are two tools which can be used to let git diff odt files: odt2txt and oodiff.

See this resource for details on how to set this up (also includes information on Mercurial and SVN.)

Snippet of above instructions (for git >= 1.6.1):

  • First, install odt2txt, and configure git to allow it to run it, by adding this to ~/.gitconfig:

    [diff "odf"]
          textconv=odt2txt
    
  • Now, for each project, you just need to ask git to use this driver in .gitattributes or $GIT_DIR/info/attributes, like this:

    *.ods diff=odf
    *.odt diff=odf
    *.odp diff=odf
    
Cas
  • 6,123
  • 3
  • 36
  • 35
YurB
  • 633
  • 5
  • 10
  • You can add .odm files too. Versining is useful when you have multiple odt files, that are merged into one .odm. – Lyokolux Jul 11 '22 at 12:13
10

Have you considered using LaTeX instead of doc or odt? This way you can edit the documents with any text editor and get good looking results. Better yet: you have proper diffs between revisions (no matter the SCM you use).

If you don't like the idea of editing the document in a simple text editor take a look at LyX. It provides a gui for editing documents like you would get in normal document editors.

For git hosting solutions you can use:

  1. github (if your documents are open-source, which I don't think)
  2. bitbucket (offers unlimited repositories, with unlimited space and up to 5 users for project)
Igor Popov
  • 9,795
  • 7
  • 55
  • 68
  • is it easy to merge conflicts in Lyx ? – MhdSyrwan Jan 10 '12 at 15:38
  • @MhdSyrwan: I would suggest you to use a specialized merge tool. For example I use: **p4merge** (from Perforce). More info in this question: http://stackoverflow.com/questions/426026/git-on-windows-how-do-you-set-up-a-mergetool – Igor Popov Jan 10 '12 at 18:38
  • 1
    but any other tool won't understand LateX !! they will see it as complex text that i can't understand to merge ,is there any way to set the Lyx compare tool as the merge tool ? – MhdSyrwan Jan 10 '12 at 21:16
  • I haven't used LyX myself so I can't give you to many details related to it. As far as I know, p4merge will show you the content as text (not rich content). – Igor Popov Jan 11 '12 at 09:54
  • 1
    Well, someone can find Markdown more appropriate for simple use-cases... Just a note. – vintprox Feb 27 '20 at 07:23
2

You can use LaTeX for text documents with format (or rtf, Rich Text File, if you prefer a method accesible to anyone), and fods for spreadsheets.