1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <article lang="en" id="git-grep(1)">
\r
6 <title>git-grep(1)</title>
\r
8 <primary>git-grep(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-grep - Print lines matching a pattern</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git grep</emphasis> [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
\r
19 [-v | --invert-match] [-h|-H] [--full-name]
\r
20 [-E | --extended-regexp] [-G | --basic-regexp]
\r
21 [-P | --perl-regexp]
\r
22 [-F | --fixed-strings] [-n | --line-number]
\r
23 [-l | --files-with-matches] [-L | --files-without-match]
\r
24 [(-O | --open-files-in-pager) [<pager>]]
\r
26 [-c | --count] [--all-match] [-q | --quiet]
\r
27 [--max-depth <depth>]
\r
28 [--color[=<when>] | --no-color]
\r
29 [--break] [--heading] [-p | --show-function]
\r
30 [-A <post-context>] [-B <pre-context>] [-C <context>]
\r
31 [-W | --function-context]
\r
32 [-f <file>] [-e] <pattern>
\r
33 [--and|--or|--not|(|)|-e <pattern>…]
\r
34 [ [--exclude-standard] [--cached | --no-index | --untracked] | <tree>…]
\r
35 [--] [<pathspec>…]</literallayout>
\r
38 <simplesect id="_description">
\r
39 <title>DESCRIPTION</title>
\r
40 <simpara>Look for specified patterns in the tracked files in the work tree, blobs
\r
41 registered in the index file, or blobs in given tree objects.</simpara>
\r
43 <simplesect id="_configuration">
\r
44 <title>CONFIGURATION</title>
\r
52 If set to true, enable <emphasis>-n</emphasis> option by default.
\r
62 If set to true, enable <emphasis>--extended-regexp</emphasis> option by default.
\r
68 <simplesect id="_options">
\r
69 <title>OPTIONS</title>
\r
77 Instead of searching tracked files in the working tree, search
\r
78 blobs registered in the index file.
\r
88 Search files in the current directory that is not managed by git.
\r
98 In addition to searching in the tracked files in the working
\r
99 tree, search also in untracked files.
\r
105 --no-exclude-standard
\r
109 Also search in ignored files by not honoring the <emphasis>.gitignore</emphasis>
\r
110 mechanism. Only useful with <emphasis>--untracked</emphasis>.
\r
120 Do not pay attention to ignored files specified via the <emphasis>.gitignore</emphasis>
\r
121 mechanism. Only useful when searching files in the current directory
\r
122 with <emphasis>--no-index</emphasis>.
\r
135 Process binary files as if they were text.
\r
148 Ignore case differences between the patterns and the
\r
159 Don't match the pattern in binary files.
\r
165 --max-depth <depth>
\r
169 For each <pathspec> given on command line, descend at most <depth>
\r
170 levels of directories. A negative value means no limit.
\r
171 This option is ignored if <pathspec> contains active wildcards.
\r
172 In other words if "a*" matches a directory named "a*",
\r
173 "*" is matched literally so --max-depth is still effective.
\r
186 Match the pattern only at word boundary (either begin at the
\r
187 beginning of a line, or preceded by a non-word character; end at
\r
188 the end of a line or followed by a non-word character).
\r
201 Select non-matching lines.
\r
214 By default, the command shows the filename for each
\r
215 match. <emphasis>-h</emphasis> option is used to suppress this output.
\r
216 <emphasis>-H</emphasis> is there for completeness and does not do anything
\r
217 except it overrides <emphasis>-h</emphasis> given earlier on the command
\r
228 When run from a subdirectory, the command usually
\r
229 outputs paths relative to the current directory. This
\r
230 option forces paths to be output relative to the project
\r
250 Use POSIX extended/basic regexp for patterns. Default
\r
251 is to use basic regexp.
\r
264 Use Perl-compatible regexp for patterns. Requires libpcre to be
\r
278 Use fixed strings for patterns (don't interpret pattern
\r
292 Prefix the line number to matching lines.
\r
301 --files-with-matches
\r
310 --files-without-match
\r
314 Instead of showing every matched line, show only the
\r
315 names of files that contain (or do not contain) matches.
\r
316 For better compatibility with <emphasis>git diff</emphasis>, <emphasis>--name-only</emphasis> is a
\r
317 synonym for <emphasis>--files-with-matches</emphasis>.
\r
326 --open-files-in-pager [<pager>]
\r
330 Open the matching files in the pager (not the output of <emphasis>grep</emphasis>).
\r
331 If the pager happens to be "less" or "vi", and the user
\r
332 specified only one pattern, the first file is positioned at
\r
333 the first match automatically.
\r
346 Output \0 instead of the character that normally follows a
\r
360 Instead of showing every matched line, show the number of
\r
367 --color[=<when>]
\r
371 Show colored matches.
\r
372 The value must be always (the default), never, or auto.
\r
382 Turn off match highlighting, even when the configuration file
\r
383 gives the default to color output.
\r
384 Same as <emphasis>--color=never</emphasis>.
\r
394 Print an empty line between matches from different files.
\r
404 Show the filename above the matches in that file instead of
\r
405 at the start of each shown line.
\r
418 Show the preceding line that contains the function name of
\r
419 the match, unless the matching line is a function name itself.
\r
420 The name is determined in the same way as <emphasis>git diff</emphasis> works out
\r
421 patch hunk headers (see <emphasis>Defining a custom hunk-header</emphasis> in
\r
422 <xref linkend="gitattributes(5)" />).
\r
434 --context <num>
\r
438 Show <num> leading and trailing lines, and place a line
\r
439 containing <emphasis>--</emphasis> between contiguous groups of matches.
\r
448 --after-context <num>
\r
452 Show <num> trailing lines, and place a line containing
\r
453 <emphasis>--</emphasis> between contiguous groups of matches.
\r
462 --before-context <num>
\r
466 Show <num> leading lines, and place a line containing
\r
467 <emphasis>--</emphasis> between contiguous groups of matches.
\r
480 Show the surrounding text from the previous line containing a
\r
481 function name up to the one before the next function name,
\r
482 effectively showing the whole function in which the match was
\r
493 Read patterns from <file>, one per line.
\r
503 The next parameter is the pattern. This option has to be
\r
504 used for patterns starting with <emphasis>-</emphasis> and should be used in
\r
505 scripts passing user input to grep. Multiple patterns are
\r
506 combined by <emphasis>or</emphasis>.
\r
525 Specify how multiple patterns are combined using Boolean
\r
526 expressions. <emphasis>--or</emphasis> is the default operator. <emphasis>--and</emphasis> has
\r
527 higher precedence than <emphasis>--or</emphasis>. <emphasis>-e</emphasis> has to be used for all
\r
538 When giving multiple pattern expressions combined with <emphasis>--or</emphasis>,
\r
539 this flag is specified to limit the match to files that
\r
540 have lines to match all of them.
\r
553 Do not output matched lines; instead, exit with status 0 when
\r
554 there is a match and with non-zero status when there isn't.
\r
560 <tree>…
\r
564 Instead of searching tracked files in the working tree, search
\r
565 blobs in the given trees.
\r
575 Signals the end of options; the rest of the parameters
\r
576 are <pathspec> limiters.
\r
582 <pathspec>…
\r
586 If given, limit the search to paths matching at least one pattern.
\r
587 Both leading paths match and glob(7) patterns are supported.
\r
593 <simplesect id="_examples">
\r
594 <title>Examples</title>
\r
598 <emphasis>git grep 'time_t' -- '*.[ch]'</emphasis>
\r
602 Looks for <emphasis>time_t</emphasis> in all tracked .c and .h files in the working
\r
603 directory and its subdirectories.
\r
609 <emphasis>git grep -e '#define' --and \( -e MAX_PATH -e PATH_MAX \)</emphasis>
\r
613 Looks for a line that has <emphasis>#define</emphasis> and either <emphasis>MAX_PATH</emphasis> or
\r
614 <emphasis>PATH_MAX</emphasis>.
\r
620 <emphasis>git grep --all-match -e NODE -e Unexpected</emphasis>
\r
624 Looks for a line that has <emphasis>NODE</emphasis> or <emphasis>Unexpected</emphasis> in
\r
625 files that have lines that match both.
\r
631 <simplesect id="_git">
\r
633 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r