Message Boards Message Boards

1
|
3315 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to compare different versions of a notebook?

Posted 2 years ago

When I am working with notebooks, I tend to make small, incremental changes which I test and save with an incrementing file name. For example, my first effort is Notebook1 which I test and, if working, save as Notebook1 and as Notebook2. I now work on Notebook2 ... you get the picture.

From time to time I need to compare one notebook with an earlier version. I have available two software packages, Code Compare and Beyond Compare, but to use them I really need to be able to convert or export the contents of the notebooks as text. I am only really interested in the code/input sections of the notebooks.

POSTED BY: Paul Newton
5 Replies
Posted 6 months ago

As noted below notebook files, .nb, are text but they have a great deal of metadata, input, output and lots of "noise"

If you want to compare the input lines in 2 notebooks, go to File/Save As and save the notebooks as "wolfram language script". The .wls is very clean and easy to compare with any line-by-line text compare tool.

At least in version 14.0 File/Save as "text" doesn't differentiate input and output, and contains all output from when the notebook last ran. It is very noisy.

Each section of inputs in the .wls file from a notebook begins with

(* ::Input:: *)

--- various input lines ---

(**)

It often ends before the (*) but sometimes the input lines are after the ( *)

There are sections for explicitly printed lines that begin with (* ::Print:: *)

Git diff works really well. Any command-line tool you know will work.

POSTED BY: John Millard
Posted 6 months ago

Great suggestion - Thank you John

POSTED BY: Paul Newton
Posted 2 years ago

Thank you, Rohit, I will look into those.

POSTED BY: Paul Newton
Posted 2 years ago

Notebooks are text files so any program that can compare text files will work on notebooks. The problem is that notebooks contain metadata such as CellChangeTimes that make it difficult to discern code changes from metadata changes.

There are functions in the Wolfram Function Repository that can help with this. SaveReadableNotebook, and ExpressionLineDiff.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

I don't have a concrete suggestion at this point, but it might be helpful to know why you need this.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract