0

Is is possible to reset notebook run information, only keep content of a jupyter notebook? Because every time I run a notebook, git will think this file is changed. I don't remember if I change the content of this notebook(some time I open a notebook for days), so I can't just checkout this notebook file for git history. If I just commit notebook to git server no matter if I make "real" change of it, it makes my git log very messy.

There some execution information is not keep in .ipynb_checkpints directory:

for example:

enter image description here

another real messy content is the output of cells.

scott huang
  • 1,868
  • 2
  • 16
  • 31

1 Answers1

0

You could add the following line to your .gitignore to simply make Git ignore the Jupyter Notebook checkpoint files:

.ipynb_checkpoints

If you don't already have a .gitignore file, this is a file that tells Git which files it can safely ignore. You can create it by simply making a file named ".gitignore", then adding the line above to the file.

If you're using Windows, this is a little harder than it should be, since the ".gitignore" file doesn't technically have a file name (only a file extension). Here's how you can do it anyway.

Also note that if you have already added any .ipynb_checkpoints files to your Git repo, you need to manually remove them before this will work. The .gitignore file does not work on files that are already tracked.

Erlend D.
  • 2,867
  • 6
  • 32
  • 53
  • mynotebook.ipynb will change if I just run it without modify content. I take a look, it keep some information of if I run this cell, something like that..actually I google it before I post his question, there are some tricks to make notebook work with git. but it's a bit complicated, So, I think if I am willing to discard some information, maybe there is a simpler solution. – scott huang Nov 01 '18 at 12:24
  • Ah, you're right, looks like there's more than the checkpoint files. Here's a writeup that tries to tackle the problem, but I have not tried it myself: http://timstaley.co.uk/posts/making-git-and-jupyter-notebooks-play-nice/ – Erlend D. Nov 01 '18 at 12:27