1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[メモ]jupyterのoutputを無視する設定

Posted at

目的

記事の目的

jupter notebookのoutputを無視してコミットする操作の自動化方法をメモする。

なぜ必要か

  • リポジトリ容量の節約
  • [Clear All Outputs]を使いたくない(ローカルには結果を残したい)
  • コードは公開OKだけど、データの中身は見せられない(社内のリモートリポジトリに部外秘データ分析コードを置きたいときなど)

環境

以下の環境で実行を確認しています。

  • OS: macOS Sequoia 15.6.1
  • git: 2.49.0
  • jupyter: 1.1.1

設定方法

以下2つの設定をすると、outputが削除された状態でコミットされる。
ローカルのノートブックにはoutputが残る。

.gitattributesファイルの設定

以下の記述を追記。

*.ipynb filter=strip-notebook-output

configの設定

リポジトリ内で以下のコマンドを実行

git config filter.strip-notebook-output.clean 'jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR'

以下のように出力されればOK.

% cat .git/config 
[core] 
        他の設定
[filter "strip-notebook-output"]
        clean = jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?