6 git-grep - Print lines matching a pattern
12 'git grep' [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
13 [-v | --invert-match] [-h|-H] [--full-name]
14 [-E | --extended-regexp] [-G | --basic-regexp]
15 [-F | --fixed-strings] [-n]
16 [-l | --files-with-matches] [-L | --files-without-match]
18 [-c | --count] [--all-match] [-q | --quiet]
20 [--color[=<when>] | --no-color]
21 [-A <post-context>] [-B <pre-context>] [-C <context>]
22 [-f <file>] [-e] <pattern>
23 [--and|--or|--not|(|)|-e <pattern>...]
24 [--cached | --no-index | <tree>...]
29 Look for specified patterns in the tracked files in the work tree, blobs
30 registered in the index file, or blobs in given tree objects.
36 Instead of searching tracked files in the working tree, search
37 blobs registered in the index file.
40 Search files in the current directory, not just those tracked by git.
44 Process binary files as if they were text.
48 Ignore case differences between the patterns and the
52 Don't match the pattern in binary files.
55 For each <pathspec> given on command line, descend at most <depth>
56 levels of directories. A negative value means no limit.
60 Match the pattern only at word boundary (either begin at the
61 beginning of a line, or preceded by a non-word character; end at
62 the end of a line or followed by a non-word character).
66 Select non-matching lines.
70 By default, the command shows the filename for each
71 match. `-h` option is used to suppress this output.
72 `-H` is there for completeness and does not do anything
73 except it overrides `-h` given earlier on the command
77 When run from a subdirectory, the command usually
78 outputs paths relative to the current directory. This
79 option forces paths to be output relative to the project
86 Use POSIX extended/basic regexp for patterns. Default
87 is to use basic regexp.
91 Use fixed strings for patterns (don't interpret pattern
95 Prefix the line number to matching lines.
98 --files-with-matches::
101 --files-without-match::
102 Instead of showing every matched line, show only the
103 names of files that contain (or do not contain) matches.
104 For better compatibility with 'git diff', `--name-only` is a
105 synonym for `--files-with-matches`.
109 Output \0 instead of the character that normally follows a
114 Instead of showing every matched line, show the number of
118 Show colored matches.
119 The value must be always (the default), never, or auto.
122 Turn off match highlighting, even when the configuration file
123 gives the default to color output.
124 Same as `--color=never`.
127 Show `context` trailing (`A` -- after), or leading (`B`
128 -- before), or both (`C` -- context) lines, and place a
129 line containing `--` between contiguous groups of
133 A shortcut for specifying `-C<num>`.
137 Show the preceding line that contains the function name of
138 the match, unless the matching line is a function name itself.
139 The name is determined in the same way as 'git diff' works out
140 patch hunk headers (see 'Defining a custom hunk-header' in
141 linkgit:gitattributes[5]).
144 Read patterns from <file>, one per line.
147 The next parameter is the pattern. This option has to be
148 used for patterns starting with `-` and should be used in
149 scripts passing user input to grep. Multiple patterns are
156 Specify how multiple patterns are combined using Boolean
157 expressions. `--or` is the default operator. `--and` has
158 higher precedence than `--or`. `-e` has to be used for all
162 When giving multiple pattern expressions combined with `--or`,
163 this flag is specified to limit the match to files that
164 have lines to match all of them.
168 Do not output matched lines; instead, exit with status 0 when
169 there is a match and with non-zero status when there isn't.
172 Instead of searching tracked files in the working tree, search
173 blobs in the given trees.
176 Signals the end of options; the rest of the parameters
177 are <pathspec> limiters.
180 If given, limit the search to paths matching at least one pattern.
181 Both leading paths match and glob(7) patterns are supported.
186 git grep 'time_t' -- '*.[ch]'::
187 Looks for `time_t` in all tracked .c and .h files in the working
188 directory and its subdirectories.
190 git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
191 Looks for a line that has `#define` and either `MAX_PATH` or
194 git grep --all-match -e NODE -e Unexpected::
195 Looks for a line that has `NODE` or `Unexpected` in
196 files that have lines that match both.
200 Originally written by Linus Torvalds <torvalds@osdl.org>, later
201 revamped by Junio C Hamano.
206 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
210 Part of the linkgit:git[1] suite