'How to prevent Git from commiting Jupyter Notebook results?
I m working on project in Jupyter Notebook.
Whenever I make a commit not only changed code and markdown columns get commited but also results from code columns.
That makes Git diffs unreadable and it is very hard to review pull requests and changes due to commiting of those code cell results.
Is there a way of preventing this?
Solution 1:[1]
I suggest setting up a precommit hook to strip notebooks of rendered content and write back to file. And git ignoring .ipynb_checkpoints as @Werner suggests.
Solution 2:[2]
You have a few options:
Jupytext (https://github.com/mwouts/jupytext), will let you open .py files as Jupyter notebooks, and since they do not store the input, the diff will be as easy as any other source code diff.
If you want to keep the .ipynb format, you can use nbdime
(https://github.com/jupyter/nbdime) which produces nicer notebook diffs (you can integrate it with git diff).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | M_Merciless |
Solution 2 | Peter W |