Git has the foreach
command to recursively enter each submodule and so some operations. I now want to narrow the scope to some specific ones.
For example, there are 100 submodules inside a git repo. At some point, several of the submodules get dirty, the dirty submodules can show up with git status -sb
. I only want to execute git clean
for these dirty submodules.
I can use git submodule foreach git clean
, however this recursively enter 100 submodules and perform the git clean
, but most of them are not needed and waste a lot of time.
What I want is some kind of git submodule foreachdirty
, or at least git submodule <submoduleName>
to execute command on specific ones. Is there such facility existing?
CodePudding user response:
Note that "running a git action in a submodule" is equivalent to :
cd path/to/submodule
git action
or
git -C path/to/submodule action
If you have a way to list your dirty submodules, you can simply run a loop. For example in bash :
# if you have listed them in a file, the command can simply be 'cat dirtylist.txt'
<command to list submodules> | while read submod; do git -C $submod clean -fd; done