使用 git commit 时如何清除 Jupyter Notebook 的输出和元数据?

oce*_*n11 17 python git jupyter-notebook

输出和元数据不用于代码审查,如果提交的话会很烦人。使用 git commit 时如何清除 Jupyter Notebook 的输出和元数据?

oce*_*n11 16

github 帖子

stackoverflow 中类似的方法

答案基于前2篇文章。

我的方法包括同时清理元数据。

将其添加到本地 .git/config

[filter "strip-notebook-output"]
clean = "jupyter nbconvert --ClearOutputPreprocessor.enabled=True --ClearMetadataPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR"
Run Code Online (Sandbox Code Playgroud)

在笔记本目录中创建一个 .gitattributes 文件,内容如下:

*.ipynb filter=strip-notebook-output
Run Code Online (Sandbox Code Playgroud)

  • 我认为每次您在存储库中触摸 git 时都会运行它(甚至像“git status”),所以要小心! (2认同)