3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.46.1.603.g94b60adee3
10 .TH "GIT\-GREP" "1" "2024-09-20" "Git 2\&.46\&.1\&.603\&.g94b60a" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-grep \- Print lines matching a pattern
35 \fIgit grep\fR [\-a | \-\-text] [\-I] [\-\-textconv] [\-i | \-\-ignore\-case] [\-w | \-\-word\-regexp]
36 [\-v | \-\-invert\-match] [\-h|\-H] [\-\-full\-name]
37 [\-E | \-\-extended\-regexp] [\-G | \-\-basic\-regexp]
38 [\-P | \-\-perl\-regexp]
39 [\-F | \-\-fixed\-strings] [\-n | \-\-line\-number] [\-\-column]
40 [\-l | \-\-files\-with\-matches] [\-L | \-\-files\-without\-match]
41 [(\-O | \-\-open\-files\-in\-pager) [<pager>]]
43 [ \-o | \-\-only\-matching ] [\-c | \-\-count] [\-\-all\-match] [\-q | \-\-quiet]
44 [\-\-max\-depth <depth>] [\-\-[no\-]recursive]
45 [\-\-color[=<when>] | \-\-no\-color]
46 [\-\-break] [\-\-heading] [\-p | \-\-show\-function]
47 [\-A <post\-context>] [\-B <pre\-context>] [\-C <context>]
48 [\-W | \-\-function\-context]
49 [(\-m | \-\-max\-count) <num>]
51 [\-f <file>] [\-e] <pattern>
52 [\-\-and|\-\-or|\-\-not|(|)|\-e <pattern>\&...\:]
53 [\-\-recurse\-submodules] [\-\-parent\-basename <basename>]
54 [ [\-\-[no\-]exclude\-standard] [\-\-cached | \-\-untracked | \-\-no\-index] | <tree>\&...\:]
55 [\-\-] [<pathspec>\&...\:]
59 Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects\&. Patterns are lists of one or more search expressions separated by newline characters\&. An empty string as search expression matches all lines\&.
64 Instead of searching tracked files in the working tree, search blobs registered in the index file\&.
69 In addition to searching in the tracked files in the working tree, search also in untracked files\&.
74 Search files in the current directory that is not managed by Git, or by ignoring that the current directory is managed by Git\&. This is rather similar to running the regular
78 option specified, but with some additional benefits, such as using pathspec patterns to limit paths; see the
82 for more information\&.
84 This option cannot be used together with
87 \fB\-\-untracked\fR\&. See also
88 \fBgrep\&.fallbackToNoIndex\fR
94 \-\-no\-exclude\-standard
96 Also search in ignored files by not honoring the
98 mechanism\&. Only useful with
99 \fB\-\-untracked\fR\&.
102 \-\-exclude\-standard
104 Do not pay attention to ignored files specified via the
106 mechanism\&. Only useful when searching files in the current directory with
107 \fB\-\-no\-index\fR\&.
110 \-\-recurse\-submodules
112 Recursively search in each submodule that is active and checked out in the repository\&. When used in combination with the
114 option the prefix of all submodule output will be the name of the parent project\(cqs
116 object\&. This option cannot be used together with
117 \fB\-\-untracked\fR, and it has no effect if
124 Process binary files as if they were text\&.
129 Honor textconv filter settings\&.
134 Do not honor textconv filter settings\&. This is the default\&.
137 \-i, \-\-ignore\-case
139 Ignore case differences between the patterns and the files\&.
144 Don\(cqt match the pattern in binary files\&.
147 \-\-max\-depth <depth>
149 For each <pathspec> given on command line, descend at most <depth> levels of directories\&. A value of \-1 means no limit\&. This option is ignored if <pathspec> contains active wildcards\&. In other words if "a*" matches a directory named "a*", "*" is matched literally so \-\-max\-depth is still effective\&.
155 \fB\-\-max\-depth=\-1\fR; this is the default\&.
161 \fB\-\-max\-depth=0\fR\&.
164 \-w, \-\-word\-regexp
166 Match the pattern only at word boundary (either begin at the beginning of a line, or preceded by a non\-word character; end at the end of a line or followed by a non\-word character)\&.
169 \-v, \-\-invert\-match
171 Select non\-matching lines\&.
176 By default, the command shows the filename for each match\&.
178 option is used to suppress this output\&.
180 is there for completeness and does not do anything except it overrides
182 given earlier on the command line\&.
187 When run from a subdirectory, the command usually outputs paths relative to the current directory\&. This option forces paths to be output relative to the project top directory\&.
190 \-E, \-\-extended\-regexp, \-G, \-\-basic\-regexp
192 Use POSIX extended/basic regexp for patterns\&. Default is to use basic regexp\&.
195 \-P, \-\-perl\-regexp
197 Use Perl\-compatible regular expressions for patterns\&.
199 Support for these types of regular expressions is an optional compile\-time dependency\&. If Git wasn\(cqt compiled with support for them providing this option will cause it to die\&.
202 \-F, \-\-fixed\-strings
204 Use fixed strings for patterns (don\(cqt interpret pattern as a regex)\&.
207 \-n, \-\-line\-number
209 Prefix the line number to matching lines\&.
214 Prefix the 1\-indexed byte\-offset of the first match from the start of the matching line\&.
217 \-l, \-\-files\-with\-matches, \-\-name\-only, \-L, \-\-files\-without\-match
219 Instead of showing every matched line, show only the names of files that contain (or do not contain) matches\&. For better compatibility with
223 \fB\-\-files\-with\-matches\fR\&.
226 \-O[<pager>], \-\-open\-files\-in\-pager[=<pager>]
228 Open the matching files in the pager (not the output of
229 \fIgrep\fR)\&. If the pager happens to be "less" or "vi", and the user specified only one pattern, the first file is positioned at the first match automatically\&. The
231 argument is optional; if specified, it must be stuck to the option without a space\&. If
233 is unspecified, the default pager will be used (see
236 \fBgit-config\fR(1))\&.
241 Use \e0 as the delimiter for pathnames in the output, and print them verbatim\&. Without this option, pathnames with "unusual" characters are quoted as explained for the configuration variable
242 \fBcore\&.quotePath\fR
244 \fBgit-config\fR(1))\&.
247 \-o, \-\-only\-matching
249 Print only the matched (non\-empty) parts of a matching line, with each such part on a separate output line\&.
254 Instead of showing every matched line, show the number of lines that match\&.
259 Show colored matches\&. The value must be always (the default), never, or auto\&.
264 Turn off match highlighting, even when the configuration file gives the default to color output\&. Same as
265 \fB\-\-color=never\fR\&.
270 Print an empty line between matches from different files\&.
275 Show the filename above the matches in that file instead of at the start of each shown line\&.
278 \-p, \-\-show\-function
280 Show the preceding line that contains the function name of the match, unless the matching line is a function name itself\&. The name is determined in the same way as
282 works out patch hunk headers (see
283 \fIDefining a custom hunk\-header\fR
285 \fBgitattributes\fR(5))\&.
288 \-<num>, \-C <num>, \-\-context <num>
290 Show <num> leading and trailing lines, and place a line containing
292 between contiguous groups of matches\&.
295 \-A <num>, \-\-after\-context <num>
297 Show <num> trailing lines, and place a line containing
299 between contiguous groups of matches\&.
302 \-B <num>, \-\-before\-context <num>
304 Show <num> leading lines, and place a line containing
306 between contiguous groups of matches\&.
309 \-W, \-\-function\-context
311 Show the surrounding text from the previous line containing a function name up to the one before the next function name, effectively showing the whole function in which the match was found\&. The function names are determined in the same way as
313 works out patch hunk headers (see
314 \fIDefining a custom hunk\-header\fR
316 \fBgitattributes\fR(5))\&.
319 \-m <num>, \-\-max\-count <num>
321 Limit the amount of matches per file\&. When using the
324 \fB\-\-invert\-match\fR
325 option, the search stops after the specified number of non\-matches\&. A value of \-1 will return unlimited results (the default)\&. A value of 0 will exit immediately with a non\-zero status\&.
332 worker threads to use\&. See
333 \fINOTES ON THREADS\fR
338 for more information\&.
343 Read patterns from <file>, one per line\&.
345 Passing the pattern via <file> allows for providing a search pattern containing a \e0\&.
347 Not all pattern types support patterns containing \e0\&. Git will error out if a given pattern type can\(cqt support such a pattern\&. The
348 \fB\-\-perl\-regexp\fR
349 pattern type when compiled against the PCRE v2 backend has the widest support for these types of patterns\&.
351 In versions of Git before 2\&.23\&.0 patterns containing \e0 would be silently considered fixed\&. This was never documented, there were also odd and undocumented interactions between e\&.g\&. non\-ASCII patterns containing \e0 and
352 \fB\-\-ignore\-case\fR\&.
354 In future versions we may learn to support patterns containing \e0 for more search backends, until then we\(cqll die when the pattern type in question doesn\(cqt support them\&.
359 The next parameter is the pattern\&. This option has to be used for patterns starting with
361 and should be used in scripts passing user input to grep\&. Multiple patterns are combined by
365 \-\-and, \-\-or, \-\-not, ( \&...\: )
367 Specify how multiple patterns are combined using Boolean expressions\&.
369 is the default operator\&.
371 has higher precedence than
374 has to be used for all patterns\&.
379 When giving multiple pattern expressions combined with
380 \fB\-\-or\fR, this flag is specified to limit the match to files that have lines to match all of them\&.
385 Do not output matched lines; instead, exit with status 0 when there is a match and with non\-zero status when there isn\(cqt\&.
390 Instead of searching tracked files in the working tree, search blobs in the given trees\&.
395 Signals the end of options; the rest of the parameters are <pathspec> limiters\&.
400 If given, limit the search to paths matching at least one pattern\&. Both leading paths match and glob(7) patterns are supported\&.
402 For more details about the <pathspec> syntax, see the
405 \fBgitglossary\fR(7)\&.
409 \fBgit grep \*(Aqtime_t\*(Aq \-\- \*(Aq*\&.[ch]\*(Aq\fR
413 in all tracked \&.c and \&.h files in the working directory and its subdirectories\&.
416 \fBgit grep \-e \*(Aq#define\*(Aq \-\-and \e( \-e MAX_PATH \-e PATH_MAX \e)\fR
418 Looks for a line that has
426 \fBgit grep \-\-all\-match \-e NODE \-e Unexpected\fR
428 Looks for a line that has
432 in files that have lines that match both\&.
435 \fBgit grep solution \-\- :^Documentation\fR
438 \fBsolution\fR, excluding files in
439 \fBDocumentation\fR\&.
441 .SH "NOTES ON THREADS"
443 The \fB\-\-threads\fR option (and the \fBgrep\&.threads\fR configuration) will be ignored when \fB\-\-open\-files\-in\-pager\fR is used, forcing a single\-threaded execution\&.
445 When grepping the object store (with \fB\-\-cached\fR or giving tree objects), running with multiple threads might perform slower than single\-threaded if \fB\-\-textconv\fR is given and there are too many text conversions\&. Thus, if low performance is experienced in this case, it might be desirable to use \fB\-\-threads=1\fR\&.
448 Everything below this line in this section is selectively included from the \fBgit-config\fR(1) documentation\&. The content is the same as what\(cqs found there:
452 If set to true, enable
459 If set to true, enable the
466 Set the default matching behavior\&. Using a value of
472 \fB\-\-basic\-regexp\fR,
473 \fB\-\-extended\-regexp\fR,
474 \fB\-\-fixed\-strings\fR, or
475 \fB\-\-perl\-regexp\fR
476 option accordingly, while the value
479 \fBgrep\&.extendedRegexp\fR
480 option to choose between
486 grep\&.extendedRegexp
488 If set to true, enable
489 \fB\-\-extended\-regexp\fR
490 option by default\&. This option is ignored when the
491 \fBgrep\&.patternType\fR
492 option is set to a value other than
498 Number of grep worker threads to use\&. If unset (or set to 0), Git will use as many threads as the number of logical cores available\&.
503 If set to true, enable
508 grep\&.fallbackToNoIndex
510 If set to true, fall back to
511 \fBgit grep \-\-no\-index\fR
514 is executed outside of a git repository\&. Defaults to false\&.
518 Part of the \fBgit\fR(1) suite