gitgit-grep

"git grep <pattern>" for just python (or any type of) files?


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?


Solution

  • You can use :

    Sytntax

    git grep <pattern> -- '*.<ext>'
    

    Where :

    Example

    git grep HelloWorld -- '*.json'