Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable shell options in git?

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?

like image 809
manol Avatar asked Jul 14 '26 01:07

manol


1 Answers

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.

like image 195
kynan Avatar answered Jul 15 '26 15:07

kynan