How to skip files belonging to a git submodule?

Viewed 114

I would like to mass-update files in a script, using the following command:

grep -l -r -E "..." . | while read -r FILE ; do
    # How to do the next line only for files that are not in submodules?
    sed -i '' -E '...' "${FILE}"
done

However, I have git submodules and do not want to update files contained in those submodules. Short of maintaining a blacklist of paths where the submodules are, is there any way to check if a file belongs to a submodule or skip them altogether?

1 Answers

If you can use git grep directly—Git's grep is pretty capable, but there may be minor differences from the system variant to watch out for—this sidesteps the problem nicely since git grep only looks at the right files in the first place.

(Mostly, it should just be a matter of replacing grep with git grep.)

Related