24

I have started using IPython notebook quite a bit for writing up draft sections for my dissertation. However, given two versions of a draft (i.e., notebook), I would like to be able to generate some form of diff output to show what has changed. Does anyone know if this is currently possible, either through IPython notebook itself, or through some extension?

naitsirhc
  • 5,274
  • 2
  • 23
  • 16

7 Answers7

15

Notebook diff can be generated with nbdime. After installing nbdime you can run following to see notebook diff in browser:

> nbdiff-web notebook_1.ipynb notebook_2.ipynb

If you are using Github for version control you can use ReviewNB for Notebook diff. It lets you login via Github and browse commits/pull-request diff on your repo. You'll see visual diff like below:

enter image description here

amirathi
  • 436
  • 4
  • 7
6

1- VS Code has added to its Aug 2020 version see here

2- try nbdime

Vahab
  • 307
  • 4
  • 7
  • Don't feel bad because I'm commenting on your post, it's simply the most recent mentioning nbdime. The web-based front-end failed to show the very first pair of notebooks I tried. The backend seems to spit out compare results but of course it is unable to handle image content and you get console spam. nbdime isn't ready for prime time yet. – StarShine Apr 10 '21 at 12:07
6

Try the following steps:

  1. Install nbdime by typing pip install nbdime on a terminal.
  2. Integrate with Git by typing nbdime config-git --enable --global on a terminal.
  3. Type nbdiff-web path/to/notebook.ipynb on a terminal.

You can choose to ignore certain types of cells. For example, if you want to ignore output cells, type: nbdiff-web --ignore-outputs path/to/notebook.ipynb.

More information on the different diff options here: https://nbdime.readthedocs.io/en/latest/cli.html#common-diff-options

Giorgos Fou
  • 61
  • 1
  • 1
  • Which versions are being compared? I tried the commands given and got null response, so perhaps the notebook is being compared with itself. – David Epstein Sep 24 '21 at 13:38
  • By "path" do you mean the path of the file, for example on a Unix system, or do you mean the web-address on, for example, Github? – David Epstein Sep 24 '21 at 15:22
4

Another utility from the git issue that looks to have gotten official traction is nbdime.

dfrankow
  • 20,191
  • 41
  • 152
  • 214
3

Since this question was answered, NBdiff, a diffing and merging tool for the IPython Notebook appeared on GitHub. Unfortunately, it has yet to be updated for Jupyter / IPython 3 Notebook format.

dfrankow
  • 20,191
  • 41
  • 152
  • 214
Aristide
  • 3,606
  • 2
  • 30
  • 50
2

Not yet. This is a often a requested feature, but there are different "level" of diff you might want. Do you want only diff of codecell, or also output, what about prompt number ? etc, etc.

Lots of people have chimed in but nobody really took the time to wrote anything, even if notebook are pretty "simple" json file where cell "just" need to be "aligned" then produce a diffed-json notebook.

Matt
  • 27,170
  • 6
  • 80
  • 74
1

Curvenote provides a chrome extension that allows you to put your notebook in version control and then you can diff individual cells nbdime style, but also see previous outputs (plots, tables, streams,...) generated by the different versions of your code.

Diff Jupyter Notebook Cells

stevejpurves
  • 923
  • 1
  • 7
  • 12