Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

nbdime - version control for Jupyter notebooks

Documentation: https://nbdime.readthedocs.io

With nbdime installed, in JupyterLab you’ll see a little “git” button on the toolbar for any notebook that’s under version control. Clicking on that button will show you a diff of the notebook’s state vs the version in git (the equivalent of doing at the command-line git diff <this-notebook>), in a new JupyterLab tab.

To use nbdime on a hosted hub, first we define the URL of our hub:

Accessing nbdime on the hub

The nbdiff-web command should be executed with these parameters. You can pick the port number at will, but you need to pick a number so you can set the same value both in the -p and --base-url flags; using port 9999 for illustration:

nbdiff-web --ip 0.0.0.0 -p 9999 --base-url ${JUPYTERHUB_SERVICE_PREFIX}proxy/absolute/9999

in the folder where the notebooks under git version control that you want to diff reside.

And then the following URL should be accessed:

https://hub.cryointhecloud.com/user-redirect/proxy/absolute/9999/difftool

If you are working regularly in a folder, you can leave this command running and reload the page to see any new changes you’ve made.

When instead accessing a manual diff of two files, that on a local machine would be done with nbdiff-web nb1.ipynb nb2.ipynb, you should similarly execute

nbdiff-web --ip 0.0.0.0 -p 9999 --base-url ${JUPYTERHUB_SERVICE_PREFIX}proxy/absolute/9999 nb1.ipynb nb2.ipynb

but then you need to access the URL:

https://hub.cryointhecloud.com/user-redirect/proxy/absolute/9999/diff?base=nb1.ipynb&remote=nb2.ipynb

Code to semi-automate the above

Let’s first define some little utilities that we’ll use to display cleaner code later:

Now, define the command to run:

'nbdiff-web --ip 0.0.0.0 -p 9999 --base-url ${JUPYTERHUB_SERVICE_PREFIX}proxy/absolute/9999'

And our base url:

'https://hub.cryointhecloud.com/user-redirect/proxy/absolute/9999'

Next, define the location of the file/directory we want to diff:

Now, go to the folder with your project with:

<IPython.core.display.Markdown object>

and, once there, run the command:

<IPython.core.display.Markdown object>

and then visit <IPython.core.display.Markdown object> (<IPython.core.display.Markdown object>).

If using nbdime to diff two local files (instead of the git state), there’s a small change:

In this case, with two explicit files to compare, we can again go to the folder with this content:

<IPython.core.display.Markdown object>

and, once there, run the command:

<IPython.core.display.Markdown object>

and and then visit <IPython.core.display.Markdown object>.