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.41.0.rc0.4.g004e0f790f
10 .TH "GIT\-GREP" "1" "2023\-05\-17" "Git 2\&.41\&.0\&.rc0\&.4\&.g00" "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 | \-\-no\-index | \-\-untracked] | <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 Search files in the current directory that is not managed by Git\&.
75 In addition to searching in the tracked files in the working tree, search also in untracked files\&.
78 \-\-no\-exclude\-standard
80 Also search in ignored files by not honoring the
82 mechanism\&. Only useful with
83 \fB\-\-untracked\fR\&.
88 Do not pay attention to ignored files specified via the
90 mechanism\&. Only useful when searching files in the current directory with
91 \fB\-\-no\-index\fR\&.
94 \-\-recurse\-submodules
96 Recursively search in each submodule that is active and checked out in the repository\&. When used in combination with the <tree> option the prefix of all submodule output will be the name of the parent project\(cqs <tree> object\&. This option has no effect if
103 Process binary files as if they were text\&.
108 Honor textconv filter settings\&.
113 Do not honor textconv filter settings\&. This is the default\&.
116 \-i, \-\-ignore\-case
118 Ignore case differences between the patterns and the files\&.
123 Don\(cqt match the pattern in binary files\&.
126 \-\-max\-depth <depth>
128 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\&.
134 \fB\-\-max\-depth=\-1\fR; this is the default\&.
140 \fB\-\-max\-depth=0\fR\&.
143 \-w, \-\-word\-regexp
145 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)\&.
148 \-v, \-\-invert\-match
150 Select non\-matching lines\&.
155 By default, the command shows the filename for each match\&.
157 option is used to suppress this output\&.
159 is there for completeness and does not do anything except it overrides
161 given earlier on the command line\&.
166 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\&.
169 \-E, \-\-extended\-regexp, \-G, \-\-basic\-regexp
171 Use POSIX extended/basic regexp for patterns\&. Default is to use basic regexp\&.
174 \-P, \-\-perl\-regexp
176 Use Perl\-compatible regular expressions for patterns\&.
178 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\&.
181 \-F, \-\-fixed\-strings
183 Use fixed strings for patterns (don\(cqt interpret pattern as a regex)\&.
186 \-n, \-\-line\-number
188 Prefix the line number to matching lines\&.
193 Prefix the 1\-indexed byte\-offset of the first match from the start of the matching line\&.
196 \-l, \-\-files\-with\-matches, \-\-name\-only, \-L, \-\-files\-without\-match
198 Instead of showing every matched line, show only the names of files that contain (or do not contain) matches\&. For better compatibility with
202 \fB\-\-files\-with\-matches\fR\&.
205 \-O[<pager>], \-\-open\-files\-in\-pager[=<pager>]
207 Open the matching files in the pager (not the output of
208 \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
210 argument is optional; if specified, it must be stuck to the option without a space\&. If
212 is unspecified, the default pager will be used (see
215 \fBgit-config\fR(1))\&.
220 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 core\&.quotePath (see
221 \fBgit-config\fR(1))\&.
224 \-o, \-\-only\-matching
226 Print only the matched (non\-empty) parts of a matching line, with each such part on a separate output line\&.
231 Instead of showing every matched line, show the number of lines that match\&.
236 Show colored matches\&. The value must be always (the default), never, or auto\&.
241 Turn off match highlighting, even when the configuration file gives the default to color output\&. Same as
242 \fB\-\-color=never\fR\&.
247 Print an empty line between matches from different files\&.
252 Show the filename above the matches in that file instead of at the start of each shown line\&.
255 \-p, \-\-show\-function
257 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
259 works out patch hunk headers (see
260 \fIDefining a custom hunk\-header\fR
262 \fBgitattributes\fR(5))\&.
265 \-<num>, \-C <num>, \-\-context <num>
267 Show <num> leading and trailing lines, and place a line containing
269 between contiguous groups of matches\&.
272 \-A <num>, \-\-after\-context <num>
274 Show <num> trailing lines, and place a line containing
276 between contiguous groups of matches\&.
279 \-B <num>, \-\-before\-context <num>
281 Show <num> leading lines, and place a line containing
283 between contiguous groups of matches\&.
286 \-W, \-\-function\-context
288 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
290 works out patch hunk headers (see
291 \fIDefining a custom hunk\-header\fR
293 \fBgitattributes\fR(5))\&.
296 \-m <num>, \-\-max\-count <num>
298 Limit the amount of matches per file\&. When using the
301 \fB\-\-invert\-match\fR
302 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\&.
307 Number of grep worker threads to use\&. See
311 for more information\&.
316 Read patterns from <file>, one per line\&.
318 Passing the pattern via <file> allows for providing a search pattern containing a \e0\&.
320 Not all pattern types support patterns containing \e0\&. Git will error out if a given pattern type can\(cqt support such a pattern\&. The
321 \fB\-\-perl\-regexp\fR
322 pattern type when compiled against the PCRE v2 backend has the widest support for these types of patterns\&.
324 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
325 \fB\-\-ignore\-case\fR\&.
327 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\&.
332 The next parameter is the pattern\&. This option has to be used for patterns starting with
334 and should be used in scripts passing user input to grep\&. Multiple patterns are combined by
338 \-\-and, \-\-or, \-\-not, ( \&... )
340 Specify how multiple patterns are combined using Boolean expressions\&.
342 is the default operator\&.
344 has higher precedence than
347 has to be used for all patterns\&.
352 When giving multiple pattern expressions combined with
353 \fB\-\-or\fR, this flag is specified to limit the match to files that have lines to match all of them\&.
358 Do not output matched lines; instead, exit with status 0 when there is a match and with non\-zero status when there isn\(cqt\&.
363 Instead of searching tracked files in the working tree, search blobs in the given trees\&.
368 Signals the end of options; the rest of the parameters are <pathspec> limiters\&.
373 If given, limit the search to paths matching at least one pattern\&. Both leading paths match and glob(7) patterns are supported\&.
375 For more details about the <pathspec> syntax, see the
378 \fBgitglossary\fR(7)\&.
382 \fBgit grep \*(Aqtime_t\*(Aq \-\- \*(Aq*\&.[ch]\*(Aq\fR
386 in all tracked \&.c and \&.h files in the working directory and its subdirectories\&.
389 \fBgit grep \-e \*(Aq#define\*(Aq \-\-and \e( \-e MAX_PATH \-e PATH_MAX \e)\fR
391 Looks for a line that has
399 \fBgit grep \-\-all\-match \-e NODE \-e Unexpected\fR
401 Looks for a line that has
405 in files that have lines that match both\&.
408 \fBgit grep solution \-\- :^Documentation\fR
411 \fBsolution\fR, excluding files in
412 \fBDocumentation\fR\&.
414 .SH "NOTES ON THREADS"
416 The \fB\-\-threads\fR option (and the grep\&.threads configuration) will be ignored when \fB\-\-open\-files\-in\-pager\fR is used, forcing a single\-threaded execution\&.
418 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\(cqre too many text conversions\&. So if you experience low performance in this case, it might be desirable to use \fB\-\-threads=1\fR\&.
421 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:
425 If set to true, enable
432 If set to true, enable the
439 Set the default matching behavior\&. Using a value of
445 \fB\-\-basic\-regexp\fR,
446 \fB\-\-extended\-regexp\fR,
447 \fB\-\-fixed\-strings\fR, or
448 \fB\-\-perl\-regexp\fR
449 option accordingly, while the value
452 \fBgrep\&.extendedRegexp\fR
453 option to choose between
459 grep\&.extendedRegexp
461 If set to true, enable
462 \fB\-\-extended\-regexp\fR
463 option by default\&. This option is ignored when the
464 \fBgrep\&.patternType\fR
465 option is set to a value other than
471 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\&.
476 If set to true, enable
481 grep\&.fallbackToNoIndex
483 If set to true, fall back to git grep \-\-no\-index if git grep is executed outside of a git repository\&. Defaults to false\&.
487 Part of the \fBgit\fR(1) suite