LoginSignup
9
6

More than 5 years have passed since last update.

gitでJupyter Notebookのdiffを見る

Last updated at Posted at 2017-04-26

githubはnotebookのプレビューができるので、Jupyter環境ない人に共有するのに便利と思ってレポジトリに入れたのはいいが、.ipynbの中身はJSONなのでgit diffを見てもコードの変化がわかりにくく、base64エンコードされた画像出力の差分も含んだりしていて厳しい。

nbdimeを使うと画像などの差分もテキストで見やすい形式で表示してくれて便利。

$ pip install nbdime
$ nbdime config-git --enable --system
$ git diff

git機能はおまけっぽい扱いなのか、ちょっとものたりない気もする。

  • outputは表示しないでほしい
  • execution countも表示しないでほしい
  • cellの移動も追ってほしい

出力を共有する目的がなければ、単に出力を削ってしまえばいいので、jqを使って…

$ jq 'delpaths([paths | select([.[0, 2]] == ["cells", "outputs"])])' note.ipynb

参考

9
6
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
9
6