When I'm trying to find a pattern in a git-based project, I type:
git grep <pattern>
and git searches the entire project for that pattern. Sometimes this finds matches in non-source files, which makes finding what I'm looking for harder.
How can I tell it to only search Python (.py) or some other source files?
You can use :
git grep <pattern> -- '*.<ext>'
Where :
pattern
is the pattern to look forext
is the extension,in our case it is to look in all the files that contain <ext>
git grep HelloWorld -- '*.json'