I know that, if I wanted to grep for a pattern only on files with certain extensions, I could do this:
// searches recursively and matches case insensitively in only javascript files // for "res" from the current directory grep -iIr --include=*.js res ./
I've been trying to search for a way to do this via git grep as well (to take advantage of git grep's speed from the indexes it stores with its tree), but to no avail. I saw here that excluding certain file types is not possible.
Specifying File Type To do so, we can use a special type of option that starts with two hyphens: $ grep -ri "hello" --include=*. cc Test/test.cc:Hello World!
`git grep` command is used to search in the checkout branch and local files.
To take the explanation from HoldOffHunger's answer below: grep : command. -r : recursively.
The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.
Yes, for example:
git grep res -- '*.js'
Try doing this :
find . -type f -iname '*.js' -exec grep -i 'pattern' {} +
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