grep: support newline separated pattern list
[alt-git.git] / Documentation / git-grep.txt
blobc3306f3a3b855318397e8d7f4174943f589eeb3e
1 git-grep(1)
2 ===========
4 NAME
5 ----
6 git-grep - Print lines matching a pattern
9 SYNOPSIS
10 --------
11 [verse]
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            [-P | --perl-regexp]
16            [-F | --fixed-strings] [-n | --line-number]
17            [-l | --files-with-matches] [-L | --files-without-match]
18            [(-O | --open-files-in-pager) [<pager>]]
19            [-z | --null]
20            [-c | --count] [--all-match] [-q | --quiet]
21            [--max-depth <depth>]
22            [--color[=<when>] | --no-color]
23            [-A <post-context>] [-B <pre-context>] [-C <context>]
24            [-f <file>] [-e] <pattern>
25            [--and|--or|--not|(|)|-e <pattern>...]
26            [--cached | --no-index | <tree>...]
27            [--] [<pathspec>...]
29 DESCRIPTION
30 -----------
31 Look for specified patterns in the tracked files in the work tree, blobs
32 registered in the index file, or blobs in given tree objects.  Patterns
33 are lists of one or more search expressions separated by newline
34 characters.  An empty string as search expression matches all lines.
37 CONFIGURATION
38 -------------
40 grep.lineNumber::
41         If set to true, enable '-n' option by default.
43 grep.extendedRegexp::
44         If set to true, enable '--extended-regexp' option by default.
47 OPTIONS
48 -------
49 --cached::
50         Instead of searching tracked files in the working tree, search
51         blobs registered in the index file.
53 --no-index::
54         Search files in the current directory, not just those tracked by git.
56 -a::
57 --text::
58         Process binary files as if they were text.
60 -i::
61 --ignore-case::
62         Ignore case differences between the patterns and the
63         files.
65 -I::
66         Don't match the pattern in binary files.
68 --max-depth <depth>::
69         For each <pathspec> given on command line, descend at most <depth>
70         levels of directories. A negative value means no limit.
72 -w::
73 --word-regexp::
74         Match the pattern only at word boundary (either begin at the
75         beginning of a line, or preceded by a non-word character; end at
76         the end of a line or followed by a non-word character).
78 -v::
79 --invert-match::
80         Select non-matching lines.
82 -h::
83 -H::
84         By default, the command shows the filename for each
85         match.  `-h` option is used to suppress this output.
86         `-H` is there for completeness and does not do anything
87         except it overrides `-h` given earlier on the command
88         line.
90 --full-name::
91         When run from a subdirectory, the command usually
92         outputs paths relative to the current directory.  This
93         option forces paths to be output relative to the project
94         top directory.
96 -E::
97 --extended-regexp::
98 -G::
99 --basic-regexp::
100         Use POSIX extended/basic regexp for patterns.  Default
101         is to use basic regexp.
103 -P::
104 --perl-regexp::
105         Use Perl-compatible regexp for patterns. Requires libpcre to be
106         compiled in.
108 -F::
109 --fixed-strings::
110         Use fixed strings for patterns (don't interpret pattern
111         as a regex).
113 -n::
114 --line-number::
115         Prefix the line number to matching lines.
117 -l::
118 --files-with-matches::
119 --name-only::
120 -L::
121 --files-without-match::
122         Instead of showing every matched line, show only the
123         names of files that contain (or do not contain) matches.
124         For better compatibility with 'git diff', `--name-only` is a
125         synonym for `--files-with-matches`.
127 -O [<pager>]::
128 --open-files-in-pager [<pager>]::
129         Open the matching files in the pager (not the output of 'grep').
130         If the pager happens to be "less" or "vi", and the user
131         specified only one pattern, the first file is positioned at
132         the first match automatically.
134 -z::
135 --null::
136         Output \0 instead of the character that normally follows a
137         file name.
139 -c::
140 --count::
141         Instead of showing every matched line, show the number of
142         lines that match.
144 --color[=<when>]::
145         Show colored matches.
146         The value must be always (the default), never, or auto.
148 --no-color::
149         Turn off match highlighting, even when the configuration file
150         gives the default to color output.
151         Same as `--color=never`.
153 -[ABC] <context>::
154         Show `context` trailing (`A` -- after), or leading (`B`
155         -- before), or both (`C` -- context) lines, and place a
156         line containing `--` between contiguous groups of
157         matches.
159 -<num>::
160         A shortcut for specifying `-C<num>`.
162 -p::
163 --show-function::
164         Show the preceding line that contains the function name of
165         the match, unless the matching line is a function name itself.
166         The name is determined in the same way as 'git diff' works out
167         patch hunk headers (see 'Defining a custom hunk-header' in
168         linkgit:gitattributes[5]).
170 -f <file>::
171         Read patterns from <file>, one per line.
173 -e::
174         The next parameter is the pattern. This option has to be
175         used for patterns starting with `-` and should be used in
176         scripts passing user input to grep.  Multiple patterns are
177         combined by 'or'.
179 --and::
180 --or::
181 --not::
182 ( ... )::
183         Specify how multiple patterns are combined using Boolean
184         expressions.  `--or` is the default operator.  `--and` has
185         higher precedence than `--or`.  `-e` has to be used for all
186         patterns.
188 --all-match::
189         When giving multiple pattern expressions combined with `--or`,
190         this flag is specified to limit the match to files that
191         have lines to match all of them.
193 -q::
194 --quiet::
195         Do not output matched lines; instead, exit with status 0 when
196         there is a match and with non-zero status when there isn't.
198 <tree>...::
199         Instead of searching tracked files in the working tree, search
200         blobs in the given trees.
202 \--::
203         Signals the end of options; the rest of the parameters
204         are <pathspec> limiters.
206 <pathspec>...::
207         If given, limit the search to paths matching at least one pattern.
208         Both leading paths match and glob(7) patterns are supported.
210 Examples
211 --------
213 git grep {apostrophe}time_t{apostrophe} \-- {apostrophe}*.[ch]{apostrophe}::
214         Looks for `time_t` in all tracked .c and .h files in the working
215         directory and its subdirectories.
217 git grep -e {apostrophe}#define{apostrophe} --and \( -e MAX_PATH -e PATH_MAX \)::
218         Looks for a line that has `#define` and either `MAX_PATH` or
219         `PATH_MAX`.
221 git grep --all-match -e NODE -e Unexpected::
222         Looks for a line that has `NODE` or `Unexpected` in
223         files that have lines that match both.
227 Part of the linkgit:git[1] suite