Filter .ipynb (nbformat) files to improve integration with version control systems (VCS), specifically git.
Install from PyPI:
pip install nbfilterpython -m nbfilter.clean < research.ipynb | sponge research.ipynbFrom your repository's root directory:
Run the following command to define a filter called ipynbfilter in your .git/config settings:
git config filter.ipynbfilter.clean 'python -m nbfilter.clean'Then run one of the following command sequences to trigger it for all files with the .ipynb extension:
printf '*.ipynb filter=ipynbfilter\n' >> .gitattributes # Apply filter for all contributors
git add .gitattributesor:
printf '*.ipynb filter=ipynbfilter\n' >> .git/info/attributes # Apply filter for just meTo apply it to files that are already under source control (for example, so that diffing subsequent changes produces more intelligible results):
git add --renormalize . # (re-)apply filters to all files currently under source controlor:
git add --renormalize research.ipynb # (re-)apply filters to a single file-
Min RK's
nbstripoutgist that started it all (licensed as "Public Domain").git pre-commit hook for stripping output from IPython notebooks
-
nbstripoutis a PyPI-published package that provides all its functionality through anbstripoutconsole script. -
StackOverflow question: Using IPython notebooks under version control
-
Making Git and Jupyter Notebooks play nice uses
jqinstead of Python to do the JSON modifications, for the sake of speed. -
Jupyter notebooks and version control discusses alternatives to the
.ipynbfile format that would natively improvegit diff'ing (specifically, YAML with some additional constraints).
Copyright (c) 2018 Christopher Brown. MIT Licensed.