Since creating this Gist I've found out that this is a known issue and being worked on in JupyterLab Issue #9729.
A temporary work around until the next release of JupyterLab would be to downgrade nbformat
to v5.0.8
(at the time the last non-yanked release before v5.1.2
) which sidesteps the problem by not supporting cell IDs (and removing them from the notebook).
With the addition of cell IDs to Jupyter notebooks (c.f. JEP 62) the ability to cleanly version them, even with all output cleaned from them, has become even harder given that subsequent runs of the notebooks change the cell ID and create a non-empty diff.
Note that this only seems to be a problem in JupyterLab. :?
$ pyenv virtualenv 3.8.7 example
$ pyenv activate example
(example) $ pip install --upgrade pip setuptools wheel
(example) $ pip install -r requirements.txt
(example) $ jupyter lab
- Run
jupyter notebook
- Open
example.ipynb
- Kernel -> Restart & Run All
- Kernel -> Restart & Clear Output
- Save
example.ipynb
- Shutdown the running instance of Jupyter
git diff
This only seems to be a problem in JupyterLab, interestingly enough.
- Run
jupyter lab
- Open
example.ipynb
- Kernel -> Restart Kernel and Run All Cells
- Kernel -> Restart Kernel and Clear All Outputs
- Save
example.ipynb
- Shutdown the running instance of Jupyter
git diff
An example diff is included in clean_run.diff
.