12

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
  • 4,514
  • 1
  • 22
  • 16

8 Answers8

7

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
  • 326
  • 3
  • 6
4

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

2- try nbdime

Vahab
  • 181
  • 2
  • 5
  • 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
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
  • 18,326
  • 38
  • 134
  • 193
Aristide
  • 2,998
  • 2
  • 25
  • 45
3

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

dfrankow
  • 18,326
  • 38
  • 134
  • 193
3

A lot of time has passed since the original question, but this is still a relevant question in 2020. There are good solutions today.

There's nbdime for diffing locally, as amirathi mentioned and kindly provided a CLI example.

We also have notebook diffing in DAGsHub, which we use in Data-Science related pull requests.

Disclaimer: I'm the co-founder of DAGsHub

Tolstoyevsky
  • 472
  • 5
  • 13
  • While you disclose your affiliation, this answer is spam. You assert that the problem can be solved without demonstration, and you link offsite where actual answer content resides. Refer to the points "Don't tell - show!" and "Don't include links except to _support_ what you've written." on [this page](https://stackoverflow.com/help/promotion). In general, answers should be self contained. – kdbanman Jan 27 '21 at 18:00
3

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

  • 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
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
  • 26,019
  • 6
  • 79
  • 73
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
  • 888
  • 1
  • 7
  • 10