views:

276

answers:

3

Mathematica notebooks are, of course, plaintext files -- it seems reasonable to expect that they should play nice with a version-control system (git in my case, although I doubt the specific system matters). But the fact is that any .nb file is full of cache information, timestamps, and other assorted metadata. Scads of it.

Which means that limited version control is possible -- commits and rollbacks work fine. Merging, though, is a disaster. Mathematica won't open a file with merge markers in it, and a text editor is no way to go through a .nb file.

Has anyone had any luck putting a notebook under version control? How?

A: 

You should only get merge markers if the source control system detects changes to a single line by multiple users.

The source control system adds markers to make if very clear where the conflicts are, and to force you to manually remove them (as you resolve each conflict). There is no way for a source control system to know how to do it automatically for you.

If the file is text, but is designed to be read by a program only, it may have no end of line characters at all (or very long lines). Therefore if multiple people are working on such a file you'll get many merge conflicts.

I'm not familiar with the nb file format, but in general the solution to this problem is to ensure only one person is working on a file at a time (ie use an exclusive check-out mode for nb files).

Ash
The file format is important to the question. In practice, it's not particularly long-lined. The problem, as I mentioned, is that it's full of metadata.I know what the merge process is all about, but for the most part we aren't dealing with the problem of reconciling two versions of the code -- for the most part the conflict is in metadata, and I don't think we care which version we take. In the cases where we do have to merge code by hand, the question is asking about useful ways of doing that.Exclusive checkout is the obvious answer, but I'm hoping to keep it as a last resort.
Etaoin
+7  A: 
Michael Pilat
Thanks! Doesn't solve my whole problem, but it gets me most of the way there -- I'll just try to avoid having to merge the actual cell contents, and slog through it in a text editor if absolutely necessary. :)
Etaoin
Another option that you might want to disable is TrackCellChangeTimes
krawyoti
+2  A: 

Not a solution to your merging problem exactly, but this is how we handle notebooks and source control in my team. Basically, we treat Mathematica notebooks the way we'd treat binary files. They're checked-in, but:

  • we always keep a pdf copy alongside the .nb (backup for restoring the information in case we lose, for some reason, the capability of readings .nb files. Still proprietary format, but a bit more widespread, and chances are both Adobe and Wolfram won't simultaneously disappear)
  • we do not allow merges
  • we code-review only the final product (the rendered notebook) instead of the .nb file.

We mostly use Mathematica for small proofs, explorations and sidetracks, so the above procedure works fine for us (our main documentation is in LaTeX, which produces friendlier documentation for non-mathematicians/non-programmers)

Kena