Fetching contributors…
Cannot retrieve contributors at this time
50 lines (36 sloc) 741 Bytes
layout title date excerpt categories
Git grep
2017-05-07 13:13:53 -4000
How to grep files in your Git repository.
git grep

A useful command to search contents within a Git repository is git grep:

$ git grep <pattern>


For example, to see the files and lines where text is foo:

$ git grep foo

To also see line numbers:

$ git grep -n foo

To see only the files:

$ git grep -l foo

To search within commit reference(s):

$ git grep foo my_branch
$ git grep foo HEAD~3
$ git grep foo abc1234 def5678

To search with regex:

$ git grep -e "^foo"
$ git grep -e foo --or bar
$ git grep -e "^foo" --and -e "bar$"