Comments (11)
Here's how I accomplished it:
git filter-branch --tree-filter 'if [ -f foo.ipynb ]; then nbstripout foo.ipynb; fi'
The if
syntax is because if foo.ipynb
was not checked in from the first commit, then nbstripout
will fail and the filter-branch
operation will abort. Another way to avoid that would be to add an --ignore-unmatch
flag to nbstripout
, like git rm
has, which would be pretty straightforward.
This script is great, by the way. Now, if only there was a way to get git diff
to ignore cell output too...
from nbstripout.
Thanks for this. It worked great. Any reason it's not been added to the README yet? Here's an update that uses --index-filter and operates on all ipynb-files in the repo:
git filter-branch -f --index-filter '
git checkout -- :*.ipynb
find . -name '*.ipynb' -exec nbstripout {} +
git add . --ignore-removal
'
If the repo is large and the notebooks are in a subdirectory it will run faster with git checkout -- :<subdir>/*.ipynb
. You'll get a warning from git for commits where there is no notebook. If your really annoyed by this you can pipe stderr to /dev/null.
Naturally, if your repo contains mainly notebooks, you might as well use --tree-filter:
git filter-branch -f --tree-filter 'find . -name '*.ipynb' -exec nbstripout {} +'
from nbstripout.
Yes, you can do this already by calling the nbstripout
binary in a git filter-branch
pipeline. I don't have a command line handy, but if you're happy to craft one, I'd be happy to add it to the README!
from nbstripout.
Thanks, that was about the command I would have imagined. Have you tried with --index-filter
too?
Note sure what you mean about diff
? If you install the nbstripout filter it will also be used by git diff
...
from nbstripout.
Thanks, that was about the command I would have imagined. Have you tried with --index-filter too?
No, I only tried --tree-filter
, is there an advantage to one or the other?
If you install the nbstripout filter it will also be used by git diff...
Hah, you're totally right, forgot to install it after running the filter-branch
. Ok, this script is awesome!
from nbstripout.
The --index-filter
is faster since it does not need to check out the work tree but only works with the index directly. But I guess in your case speed was not a concern!
from nbstripout.
Yes, took about 10 seconds :) thanks for your help
from nbstripout.
Pleasure. Close the issue if you're satisfied! :)
from nbstripout.
@belteshassar Good point adding it to the README, will do that.
from nbstripout.
Hi, I am a bit late to the party, but can we update this to use git filter-repo
instead of git filter-branch
?
It is now the git-recommended best practice to rewrite history (https://github.com/newren/git-filter-repo/).
I am not very familiar with it though so can't really tell you the exact command.
from nbstripout.
Thanks, good suggestion! I hadn't heard for git filter-repo
before and it was new to me that it's now recommended over git filter-branch
. I'm reluctant to make this change though since
- I'm not familiar with
git filter-repo
and have never used it - It's not a built-in command for git and needs to be installed separately afaict
If anyone has experience and wants to send a PR I'm happy to consider!
from nbstripout.
Related Issues (20)
- Evaluate docshtest instead of cram
- Setting up the git filter using `.gitattributes` gives `Installation failed: git is not on path!` error HOT 5
- Allow stripping outputs from `init_cell` cells. HOT 4
- Can I use nbstripout in Github action as a test ? HOT 17
- `--dry-run` should exit non-0 if files would be updated HOT 1
- Should be agnosting on trailing blank lines HOT 9
- [Feature Request] Process Folders (Batch / Bulk) HOT 1
- Doesn't strip out pycharm metadata HOT 9
- New release HOT 2
- Replace cram with prysk HOT 2
- Read config from `setup.cfg` HOT 1
- Option to error on cell outputs exceeding `--max-size` HOT 4
- It is recommended to remove pytest-runnner from setup_requires in setup.py HOT 4
- Strip output_type=stderr only, with keep_output? HOT 4
- Possible nbstripout-fast integration HOT 6
- Prevent committing notebooks with errors in cell outputs HOT 6
- Specifying Python executable path in `nbstripout --install`
- 'nbstripout' is not recognized as an internal or external command, operable program or batch file. HOT 2
- Not compatible with `pre-commit-hooks/pretty-format-json` hook HOT 4
- `git config filter.nbstripout.extrakeys ` support for `attachments`? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbstripout.