How do I manage code written in IPython Notebook with Git?

Asked 2 years ago, Updated 2 years ago, 54 views

I would like to manage the code I wrote in IPython Notebook with Git. Committing *.ipynb makes it hard to see the difference.

Leave the advantages of executing code on a cell-by-cell basis. Is there any way to understand the difference easily with Git?

git python

2022-09-30 20:28

1 Answers

Source: Popular questions here

I don't use iPython, but I haven't received an answer yet, so I'll let you know that I found it.
There seems to be no proper way to do it at the moment (December 2014), but I think I can do something about it with で below.
And with Resolution 2, I think I'll be able to do it as it is now.

コ A way to make commitments and differences normal. Source

Create a git filter.For example: ~/bin/ipynb_output_filter.py

#!/usr/bin/python

import sys
from IPython.nbformat.current import read, write

json_in=read(sys.stdin, 'json')

for sheet in json_in.worksheets:
    for cell in sheet.cells:
        if "outputs" in cell:
            cell.outputs=[]
        if "prompt_number" in cell:
            cell.prompt_number='"

write(json_in, sys.stdout, 'json')

Change the file to executable: chmod+x~/bin/ipynb_output_filter.py

Add or create new to ~/.gitattributes

*.ipynb filter=dropoutput_ipynb

Set the git filter with the following command:

 git config --global core.attributesfile~/.gitattributes
git config --global filter.dropoutput_ipynb.clean~/bin/ipynb_output_filter.py
git config --global filter.dropoutput_ipynb.smudge cat

Problem:

  • After committing, no output data remains!
  • The source may also have details.

iPStay the iPython.Source

I don't understand clearly yet, but everyone seems to be having trouble with this problem, so I'm sure it will be solved someday.
I asked how to use it, so I'll upload it here when I get the answer.


2022-09-30 20:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.