I want to use extended globbing in an "index-filter" , e.g.
git filter-branch --index-filter "git rm --cached --ignore-unmatched Modules/!(ModuleA|ModuleB)"
but I get an error:
eval: line 336: syntax error near unexpected token `('
I already tried:
git filter-branch --index-filter "shopt -s extglob && git rm --cached
--ignore-unmatched Modules/!(ModuleA|ModuleB)"
So the general question is: how do I enable specific shell options for the shell used to evaluate these expressions?
You can circumvent the problem by having your shell invoking git filter-branch evaluate the glob for you (assuming you enabled extglob there):
git filter-branch --index-filter "git rm --cached --ignore-unmatch $(ls -xd Modules/!(ModuleA|ModuleB))"
Update: You need to supply parameters to ls: -x to separate entries by space instead of new line and -d to print the directory name instead of its contents. For more than a handful of files you may also need to add -w 1000 (or a similarly large number) to make ls assume a very wide terminal and fit everything in a single line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With