The output and metadata is not for code reviewing and it is annoying if committed. How to clear Jupyter Notebook's output and metadata when using git commit?
This answer is based on these 2 posts:
My approach includes cleaning metadata at the same time.
Add this to your local .git/config
[filter "strip-notebook-output"]
clean = "jupyter nbconvert --ClearOutputPreprocessor.enabled=True --ClearMetadataPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR"
Create a .gitattributes
file in your directory with notebooks, with this content:
*.ipynb filter=strip-notebook-output
The Previous Setting for .git/config
requires you have a default python env containing jupyter nbconvert
.
The Following Setting (Recommended) for the config can bypass the default env.
git
conda create -n git --override-channels --strict-channel-priority -c conda-forge --yes python=3.12
conda activate git
pip install nbconvert
D:/conda/win/envs/
. Then you can set the config file as following:
[filter "strip-notebook-output"]
clean = "D:/conda/win/envs/git/Scripts/jupyter-nbconvert.exe --ClearOutputPreprocessor.enabled=True --ClearMetadataPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With