diff --git a/.gitattributes b/.gitattributes index 472d2aa..55e1ec6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -*.ipynb filter=nbstrip +*.ipynb filter=ipynb_stripout diff --git a/README.md b/README.md index 1185d5a..ecd2e48 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,32 @@ -ipynb_template -============== +# ipynb_stripout -Template for creating a new git repo for an ipython notebook +Output cells make it difficult to manage iPython notebooks under Git. Diffs become noisy and merge conflicts become common. -1. Clone this repository -1. Rename the directory to something meaningful +This has been adapted from cfriedline's [ipynb_template](https://github.com/cfriedline/ipynb_template) and minrk's original [gist](https://gist.github.com/minrk/6176788) with the goal of making output stripping as easy as possible. -1. Make sure `nbstripout` is in your path and chmod +x +## 1) Install (OS X) -1. Add the following to your .gitconfig: +First you need to install the `ipynb_stripout` script. Run the following from your terminal: - [filter "nbstrip"] - clean = /home/cfriedline/bin/nbstripout - smudge =cat - required + wget -O /usr/local/bin/ipynb_stripout "https://raw.githubusercontent.com/jond3k/ipynb_stripout/master/ipynb_stripout" + chmod +x /usr/local/bin/ipynb_stripout -1. create a new github repo and change the origin in `.git/config` - - git remote set-url origin git@github.com:cfriedline/[new_repo].git +## 2) Configure git + +To make it optionally available to all your git repositories: + + git config --global filter.ipynb_stripout.clean ipynb_stripout + git config --global filter.ipynb_stripout.smudge cat + git config --global filter.ipynb_stripout.required + + +## 3) Add to repository + +Go to the root of the repository you want to add it to and `.gitattributes` with the following line: + + echo "*.ipynb filter=ipynb_stripout" >> .gitattributes + +Now you can commit the attributes. + + git add .gitattributes + git commit -m "Added ipynb_stripout. See https://github.com/jond3k/ipynb_stripout" .gitattributes diff --git a/nbstripout b/ipynb_stripout similarity index 78% rename from nbstripout rename to ipynb_stripout index 7e4c88f..6507689 100755 --- a/nbstripout +++ b/ipynb_stripout @@ -1,10 +1,6 @@ #!/usr/bin/env python """strip outputs from an IPython Notebook -Opens a notebook, strips its output, and writes the outputless version to the original file. - -Useful mainly as a git pre-commit hook for users who don't want to track output in VCS. - This does mostly the same thing as the `Clear All Output` command in the notebook UI. Adapted from rom https://gist.github.com/minrk/6176788 to work with @@ -15,7 +11,7 @@ import sys #You may need to do this for your script to work with GitX or Tower: #sys.path.append("/Users/chris/anaconda/envs/conda/lib/python2.7/site-packages") -from IPython.nbformat import v4 +from nbformat import v4 def strip_output(nb): """strip the outputs from a notebook object""" diff --git a/nbstripout_v3 b/ipynb_stripout_v3 similarity index 82% rename from nbstripout_v3 rename to ipynb_stripout_v3 index 5c2bfb8..21a61a4 100755 --- a/nbstripout_v3 +++ b/ipynb_stripout_v3 @@ -1,10 +1,6 @@ #!/usr/bin/env python """strip outputs from an IPython Notebook -Opens a notebook, strips its output, and writes the outputless version to the original file. - -Useful mainly as a git pre-commit hook for users who don't want to track output in VCS. - This does mostly the same thing as the `Clear All Output` command in the notebook UI. Adapted from rom https://gist.github.com/minrk/6176788 to work with