3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.44.0.548.g91ec36f2cc
10 .TH "GIT\-GREP" "1" "2024\-04\-09" "Git 2\&.44\&.0\&.548\&.g91ec36" "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>\&...]
60 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\&.
65 Instead of searching tracked files in the working tree, search blobs registered in the index file\&.
70 In addition to searching in the tracked files in the working tree, search also in untracked files\&.
75 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
79 option specified, but with some additional benefits, such as using pathspec patterns to limit paths; see the
83 for more information\&.
85 This option cannot be used together with
88 \fB\-\-untracked\fR\&. See also
89 \fBgrep\&.fallbackToNoIndex\fR
95 \-\-no\-exclude\-standard
97 Also search in ignored files by not honoring the
99 mechanism\&. Only useful with
100 \fB\-\-untracked\fR\&.
103 \-\-exclude\-standard
105 Do not pay attention to ignored files specified via the
107 mechanism\&. Only useful when searching files in the current directory with
108 \fB\-\-no\-index\fR\&.
111 \-\-recurse\-submodules
113 Recursively search in each submodule that is active and checked out in the repository\&. When used in combination with the
115 option the prefix of all submodule output will be the name of the parent project\(cqs
117 object\&. This option cannot be used together with
118 \fB\-\-untracked\fR, and it has no effect if
125 Process binary files as if they were text\&.
130 Honor textconv filter settings\&.
135 Do not honor textconv filter settings\&. This is the default\&.
138 \-i, \-\-ignore\-case
140 Ignore case differences between the patterns and the files\&.
145 Don\(cqt match the pattern in binary files\&.
148 \-\-max\-depth <depth>
150 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\&.
156 \fB\-\-max\-depth=\-1\fR; this is the default\&.
162 \fB\-\-max\-depth=0\fR\&.
165 \-w, \-\-word\-regexp
167 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)\&.
170 \-v, \-\-invert\-match
172 Select non\-matching lines\&.
177 By default, the command shows the filename for each match\&.
179 option is used to suppress this output\&.
181 is there for completeness and does not do anything except it overrides
183 given earlier on the command line\&.
188 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\&.
191 \-E, \-\-extended\-regexp, \-G, \-\-basic\-regexp
193 Use POSIX extended/basic regexp for patterns\&. Default is to use basic regexp\&.
196 \-P, \-\-perl\-regexp
198 Use Perl\-compatible regular expressions for patterns\&.
200 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\&.
203 \-F, \-\-fixed\-strings
205 Use fixed strings for patterns (don\(cqt interpret pattern as a regex)\&.
208 \-n, \-\-line\-number
210 Prefix the line number to matching lines\&.
215 Prefix the 1\-indexed byte\-offset of the first match from the start of the matching line\&.
218 \-l, \-\-files\-with\-matches, \-\-name\-only, \-L, \-\-files\-without\-match
220 Instead of showing every matched line, show only the names of files that contain (or do not contain) matches\&. For better compatibility with
224 \fB\-\-files\-with\-matches\fR\&.
227 \-O[<pager>], \-\-open\-files\-in\-pager[=<pager>]
229 Open the matching files in the pager (not the output of
230 \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
232 argument is optional; if specified, it must be stuck to the option without a space\&. If
234 is unspecified, the default pager will be used (see
237 \fBgit-config\fR(1))\&.
242 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
243 \fBcore\&.quotePath\fR
245 \fBgit-config\fR(1))\&.
248 \-o, \-\-only\-matching
250 Print only the matched (non\-empty) parts of a matching line, with each such part on a separate output line\&.
255 Instead of showing every matched line, show the number of lines that match\&.
260 Show colored matches\&. The value must be always (the default), never, or auto\&.
265 Turn off match highlighting, even when the configuration file gives the default to color output\&. Same as
266 \fB\-\-color=never\fR\&.
271 Print an empty line between matches from different files\&.
276 Show the filename above the matches in that file instead of at the start of each shown line\&.
279 \-p, \-\-show\-function
281 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
283 works out patch hunk headers (see
284 \fIDefining a custom hunk\-header\fR
286 \fBgitattributes\fR(5))\&.
289 \-<num>, \-C <num>, \-\-context <num>
291 Show <num> leading and trailing lines, and place a line containing
293 between contiguous groups of matches\&.
296 \-A <num>, \-\-after\-context <num>
298 Show <num> trailing lines, and place a line containing
300 between contiguous groups of matches\&.
303 \-B <num>, \-\-before\-context <num>
305 Show <num> leading lines, and place a line containing
307 between contiguous groups of matches\&.
310 \-W, \-\-function\-context
312 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
314 works out patch hunk headers (see
315 \fIDefining a custom hunk\-header\fR
317 \fBgitattributes\fR(5))\&.
320 \-m <num>, \-\-max\-count <num>
322 Limit the amount of matches per file\&. When using the
325 \fB\-\-invert\-match\fR
326 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\&.
333 worker threads to use\&. See
334 \fINOTES ON THREADS\fR
339 for more information\&.
344 Read patterns from <file>, one per line\&.
346 Passing the pattern via <file> allows for providing a search pattern containing a \e0\&.
348 Not all pattern types support patterns containing \e0\&. Git will error out if a given pattern type can\(cqt support such a pattern\&. The
349 \fB\-\-perl\-regexp\fR
350 pattern type when compiled against the PCRE v2 backend has the widest support for these types of patterns\&.
352 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
353 \fB\-\-ignore\-case\fR\&.
355 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\&.
360 The next parameter is the pattern\&. This option has to be used for patterns starting with
362 and should be used in scripts passing user input to grep\&. Multiple patterns are combined by
366 \-\-and, \-\-or, \-\-not, ( \&... )
368 Specify how multiple patterns are combined using Boolean expressions\&.
370 is the default operator\&.
372 has higher precedence than
375 has to be used for all patterns\&.
380 When giving multiple pattern expressions combined with
381 \fB\-\-or\fR, this flag is specified to limit the match to files that have lines to match all of them\&.
386 Do not output matched lines; instead, exit with status 0 when there is a match and with non\-zero status when there isn\(cqt\&.
391 Instead of searching tracked files in the working tree, search blobs in the given trees\&.
396 Signals the end of options; the rest of the parameters are <pathspec> limiters\&.
401 If given, limit the search to paths matching at least one pattern\&. Both leading paths match and glob(7) patterns are supported\&.
403 For more details about the <pathspec> syntax, see the
406 \fBgitglossary\fR(7)\&.
410 \fBgit grep \*(Aqtime_t\*(Aq \-\- \*(Aq*\&.[ch]\*(Aq\fR
414 in all tracked \&.c and \&.h files in the working directory and its subdirectories\&.
417 \fBgit grep \-e \*(Aq#define\*(Aq \-\-and \e( \-e MAX_PATH \-e PATH_MAX \e)\fR
419 Looks for a line that has
427 \fBgit grep \-\-all\-match \-e NODE \-e Unexpected\fR
429 Looks for a line that has
433 in files that have lines that match both\&.
436 \fBgit grep solution \-\- :^Documentation\fR
439 \fBsolution\fR, excluding files in
440 \fBDocumentation\fR\&.
442 .SH "NOTES ON THREADS"
444 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\&.
446 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\&.
449 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:
453 If set to true, enable
460 If set to true, enable the
467 Set the default matching behavior\&. Using a value of
473 \fB\-\-basic\-regexp\fR,
474 \fB\-\-extended\-regexp\fR,
475 \fB\-\-fixed\-strings\fR, or
476 \fB\-\-perl\-regexp\fR
477 option accordingly, while the value
480 \fBgrep\&.extendedRegexp\fR
481 option to choose between
487 grep\&.extendedRegexp
489 If set to true, enable
490 \fB\-\-extended\-regexp\fR
491 option by default\&. This option is ignored when the
492 \fBgrep\&.patternType\fR
493 option is set to a value other than
499 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\&.
504 If set to true, enable
509 grep\&.fallbackToNoIndex
511 If set to true, fall back to
512 \fBgit grep \-\-no\-index\fR
515 is executed outside of a git repository\&. Defaults to false\&.
519 Part of the \fBgit\fR(1) suite