Is there any way to generate a diff between two ve

2019-07-07 02:32发布

问题:

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?

回答1:

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.



回答2:

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.



回答3:

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



回答4:

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: