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]
17 [(-O | --open-files-in-pager) [<pager>]]
19 [-c | --count] [--all-match] [-q | --quiet]
21 [--color[=<when>] | --no-color]
22 [-A <post-context>] [-B <pre-context>] [-C <context>]
23 [-f <file>] [-e] <pattern>
24 [--and|--or|--not|(|)|-e <pattern>...]
25 [--cached | --no-index | <tree>...]
30 Look for specified patterns in the tracked files in the work tree, blobs
31 registered in the index file, or blobs in given tree objects.
37 Instead of searching tracked files in the working tree, search
38 blobs registered in the index file.
41 Search files in the current directory, not just those tracked by git.
45 Process binary files as if they were text.
49 Ignore case differences between the patterns and the
53 Don't match the pattern in binary files.
56 For each <pathspec> given on command line, descend at most <depth>
57 levels of directories. A negative value means no limit.
61 Match the pattern only at word boundary (either begin at the
62 beginning of a line, or preceded by a non-word character; end at
63 the end of a line or followed by a non-word character).
67 Select non-matching lines.
71 By default, the command shows the filename for each
72 match. `-h` option is used to suppress this output.
73 `-H` is there for completeness and does not do anything
74 except it overrides `-h` given earlier on the command
78 When run from a subdirectory, the command usually
79 outputs paths relative to the current directory. This
80 option forces paths to be output relative to the project
87 Use POSIX extended/basic regexp for patterns. Default
88 is to use basic regexp.
92 Use fixed strings for patterns (don't interpret pattern
96 Prefix the line number to matching lines.
99 --files-with-matches::
102 --files-without-match::
103 Instead of showing every matched line, show only the
104 names of files that contain (or do not contain) matches.
105 For better compatibility with 'git diff', `--name-only` is a
106 synonym for `--files-with-matches`.
109 --open-files-in-pager [<pager>]::
110 Open the matching files in the pager (not the output of 'grep').
111 If the pager happens to be "less" or "vi", and the user
112 specified only one pattern, the first file is positioned at
113 the first match automatically.
117 Output \0 instead of the character that normally follows a
122 Instead of showing every matched line, show the number of
126 Show colored matches.
127 The value must be always (the default), never, or auto.
130 Turn off match highlighting, even when the configuration file
131 gives the default to color output.
132 Same as `--color=never`.
135 Show `context` trailing (`A` -- after), or leading (`B`
136 -- before), or both (`C` -- context) lines, and place a
137 line containing `--` between contiguous groups of
141 A shortcut for specifying `-C<num>`.
145 Show the preceding line that contains the function name of
146 the match, unless the matching line is a function name itself.
147 The name is determined in the same way as 'git diff' works out
148 patch hunk headers (see 'Defining a custom hunk-header' in
149 linkgit:gitattributes[5]).
152 Read patterns from <file>, one per line.
155 The next parameter is the pattern. This option has to be
156 used for patterns starting with `-` and should be used in
157 scripts passing user input to grep. Multiple patterns are
164 Specify how multiple patterns are combined using Boolean
165 expressions. `--or` is the default operator. `--and` has
166 higher precedence than `--or`. `-e` has to be used for all
170 When giving multiple pattern expressions combined with `--or`,
171 this flag is specified to limit the match to files that
172 have lines to match all of them.
176 Do not output matched lines; instead, exit with status 0 when
177 there is a match and with non-zero status when there isn't.
180 Instead of searching tracked files in the working tree, search
181 blobs in the given trees.
184 Signals the end of options; the rest of the parameters
185 are <pathspec> limiters.
188 If given, limit the search to paths matching at least one pattern.
189 Both leading paths match and glob(7) patterns are supported.
194 git grep 'time_t' \-- '*.[ch]'::
195 Looks for `time_t` in all tracked .c and .h files in the working
196 directory and its subdirectories.
198 git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
199 Looks for a line that has `#define` and either `MAX_PATH` or
202 git grep --all-match -e NODE -e Unexpected::
203 Looks for a line that has `NODE` or `Unexpected` in
204 files that have lines that match both.
208 Originally written by Linus Torvalds <torvalds@osdl.org>, later
209 revamped by Junio C Hamano.
214 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
218 Part of the linkgit:git[1] suite