Skip to content

Instantly share code, notes, and snippets.

@johnmarcampbell
Last active February 19, 2021 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmarcampbell/ff15e5bc2fbef3abc034fdce2c4b0bfb to your computer and use it in GitHub Desktop.
Save johnmarcampbell/ff15e5bc2fbef3abc034fdce2c4b0bfb to your computer and use it in GitHub Desktop.
A pre-commit hook for clearing output from jupyter notebooks
#!/bin/bash
# Find staged files | filter for notebooks | substitute spaces for newlines
notebooks=$( git diff --staged --name-only | grep .ipynb | tr '\n' ' ')
# If there are staged notebooks, clear them and re-add them
if [ -n "$notebooks" ]; then
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace $notebooks
git add $notebooks
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment