3

I like to version-control org files using Git. Much of my org work uses org-babel to run code that's integrated with the text. Every time I re-run the code, say as part of an export, git status sees the results of code block execution as changes to the file, leading to a long and sometimes not-too-useful commit log.

Is there a way to get Git to detect all changes (the out-of-the-box experience) or, if one wishes, to ignore changes that occur in +RESULTS: sections--anything that is output by code in the document and thus that might change from run to run (export to export)? The former would document a particular execution of code; the latter would document the "program" (org / org-babel file) that could produce such a report without specifically documenting the results of one execution.

Bill
  • 533
  • 1
  • 4
  • 16
  • Thanks for the replies so far. I'll check back in later to try some out to see if I understand them and to see if there are further options. In thinking more about this, won't Jupyter notebooks have similar problems? It's been so long since I I used Sweave that i don't recall if it changes the source file at all; I think it just produces the output file. – Bill May 16 '20 at 03:09

2 Answers2

1

You might consider a content filter driver, specifically a clean filter

clean filter

(image shown in "Customizing Git - Git Attributes", from "Pro Git book")

It can execute a script of your choice to a specific file or set of files declared in a .gitattributes.

The .gitattributes is versioned and will be visible/used by all developers.

But the content filter must be activated by a git config directive.

git config filter.xxx.clean 'script'

Since it is a local setting which needs to be repeated by all developers, so that might not be ideal, but still suitable in your case for your own individual setup.

The script could be a simple sed which would remove any +RESULT: section, makeing the file appears unchanged from Git point of view, even after an execution.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

No, there is no way to get Git to ignore changes to a tracked file. You can either have a file tracked, in which case Git will pay attention to any change to it, no matter how small, or untracked, where Git will do nothing with it.

Sometimes people recommend using git update-index to trick Git into ignoring changes to a file, but the documentation explains why this doesn't work.

You may find that you'd do better without the results in the same file, since they don't seem relevant to your actual code. It's generally not a good idea to put any sort of generated output into version control, so finding another place to put this data is probably best.

You could also implement a smudge and clean filter to remove the RESULTS output from your files (see gitattributes(7)) if you can't do that, but that's likely to be tricky and you won't be able to actually keep the existing changes, only strip out those sections.

bk2204
  • 64,793
  • 6
  • 84
  • 100