How to compare different versions of a notebook?

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.

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

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.

Thank you, Rohit, I will look into those.

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.

Great suggestion - Thank you John