blob: 343eadd4076664cc66c9d22db22d800e92cc6dc6 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-grep(1)
2===========
3
4NAME
5----
Junio C Hamano01078922006-03-10 00:31:476git-grep - Print lines matching a pattern
Junio C Hamano1a4e8412005-12-27 08:17:237
8
9SYNOPSIS
10--------
Junio C Hamano617fdb82006-05-16 02:14:2111[verse]
Junio C Hamano636c8b22010-03-07 22:25:1712'git grep' [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
Junio C Hamano97efb002006-09-16 18:16:0413 [-v | --invert-match] [-h|-H] [--full-name]
Junio C Hamano9882a522007-04-27 08:22:2214 [-E | --extended-regexp] [-G | --basic-regexp]
Junio C Hamano084228c2011-05-30 08:13:5215 [-P | --perl-regexp]
16 [-F | --fixed-strings] [-n | --line-number]
Junio C Hamano9882a522007-04-27 08:22:2217 [-l | --files-with-matches] [-L | --files-without-match]
Junio C Hamano7d449522010-07-01 00:08:5118 [(-O | --open-files-in-pager) [<pager>]]
Junio C Hamanoa476efa2008-10-10 15:31:4219 [-z | --null]
Junio C Hamano83b35472010-01-29 05:02:1320 [-c | --count] [--all-match] [-q | --quiet]
Junio C Hamano9f883862009-08-11 06:23:5221 [--max-depth <depth>]
Junio C Hamano4aa0bcc2010-03-03 05:13:1222 [--color[=<when>] | --no-color]
Junio C Hamano0ff98162012-03-31 18:19:0923 [--break] [--heading] [-p | --show-function]
Junio C Hamano617fdb82006-05-16 02:14:2124 [-A <post-context>] [-B <pre-context>] [-C <context>]
Junio C Hamano0ff98162012-03-31 18:19:0925 [-W | --function-context]
Junio C Hamano9882a522007-04-27 08:22:2226 [-f <file>] [-e] <pattern>
Junio C Hamano636c8b22010-03-07 22:25:1727 [--and|--or|--not|(|)|-e <pattern>...]
Junio C Hamano5a73f302011-10-14 05:58:3428 [ [--exclude-standard] [--cached | --no-index | --untracked] | <tree>...]
Junio C Hamano74a198f2010-02-22 00:13:3129 [--] [<pathspec>...]
Junio C Hamano1a4e8412005-12-27 08:17:2330
31DESCRIPTION
32-----------
Junio C Hamano74a198f2010-02-22 00:13:3133Look for specified patterns in the tracked files in the work tree, blobs
34registered in the index file, or blobs in given tree objects.
Junio C Hamano1a4e8412005-12-27 08:17:2335
36
Junio C Hamanoa03ac862011-04-02 04:32:2937CONFIGURATION
38-------------
39
40grep.lineNumber::
41If set to true, enable '-n' option by default.
42
43grep.extendedRegexp::
44If set to true, enable '--extended-regexp' option by default.
45
46
Junio C Hamano1a4e8412005-12-27 08:17:2347OPTIONS
48-------
Junio C Hamano617fdb82006-05-16 02:14:2149--cached::
Junio C Hamano636c8b22010-03-07 22:25:1750Instead of searching tracked files in the working tree, search
51blobs registered in the index file.
52
53--no-index::
Junio C Hamano5a73f302011-10-14 05:58:3454Search files in the current directory that is not managed by git.
55
56--untracked::
57In addition to searching in the tracked files in the working
58tree, search also in untracked files.
59
60--no-exclude-standard::
61Also search in ignored files by not honoring the `.gitignore`
62mechanism. Only useful with `--untracked`.
63
64--exclude-standard::
65Do not pay attention to ignored files specified via the `.gitignore`
66mechanism. Only useful when searching files in the current directory
67with `--no-index`.
Junio C Hamano617fdb82006-05-16 02:14:2168
Junio C Hamanoeb415992008-06-08 22:49:4769-a::
70--text::
Junio C Hamano617fdb82006-05-16 02:14:2171Process binary files as if they were text.
72
Junio C Hamanoeb415992008-06-08 22:49:4773-i::
74--ignore-case::
Junio C Hamano617fdb82006-05-16 02:14:2175Ignore case differences between the patterns and the
76files.
77
Junio C Hamano9882a522007-04-27 08:22:2278-I::
79Don't match the pattern in binary files.
80
Junio C Hamano9f883862009-08-11 06:23:5281--max-depth <depth>::
Junio C Hamano74a198f2010-02-22 00:13:3182For each <pathspec> given on command line, descend at most <depth>
Junio C Hamano9f883862009-08-11 06:23:5283levels of directories. A negative value means no limit.
Junio C Hamanobfeab4e2012-01-19 00:51:2784This option is ignored if <pathspec> contains active wildcards.
85In other words if "a*" matches a directory named "a*",
86"*" is matched literally so --max-depth is still effective.
Junio C Hamano9f883862009-08-11 06:23:5287
Junio C Hamanoeb415992008-06-08 22:49:4788-w::
89--word-regexp::
Junio C Hamano617fdb82006-05-16 02:14:2190Match the pattern only at word boundary (either begin at the
91beginning of a line, or preceded by a non-word character; end at
92the end of a line or followed by a non-word character).
93
Junio C Hamanoeb415992008-06-08 22:49:4794-v::
95--invert-match::
Junio C Hamano617fdb82006-05-16 02:14:2196Select non-matching lines.
97
Junio C Hamanoeb415992008-06-08 22:49:4798-h::
99-H::
Junio C Hamano97efb002006-09-16 18:16:04100By default, the command shows the filename for each
101match. `-h` option is used to suppress this output.
102`-H` is there for completeness and does not do anything
103except it overrides `-h` given earlier on the command
104line.
105
Junio C Hamano85e45fa2006-08-13 07:47:41106--full-name::
107When run from a subdirectory, the command usually
108outputs paths relative to the current directory. This
109option forces paths to be output relative to the project
110top directory.
111
Junio C Hamanoeb415992008-06-08 22:49:47112-E::
113--extended-regexp::
114-G::
115--basic-regexp::
Junio C Hamano617fdb82006-05-16 02:14:21116Use POSIX extended/basic regexp for patterns. Default
117is to use basic regexp.
118
Junio C Hamano084228c2011-05-30 08:13:52119-P::
120--perl-regexp::
121Use Perl-compatible regexp for patterns. Requires libpcre to be
122compiled in.
123
Junio C Hamanoeb415992008-06-08 22:49:47124-F::
125--fixed-strings::
Junio C Hamano9882a522007-04-27 08:22:22126Use fixed strings for patterns (don't interpret pattern
127as a regex).
128
Junio C Hamano617fdb82006-05-16 02:14:21129-n::
Junio C Hamano2906d342011-03-29 02:19:17130--line-number::
Junio C Hamano617fdb82006-05-16 02:14:21131Prefix the line number to matching lines.
132
Junio C Hamanoeb415992008-06-08 22:49:47133-l::
134--files-with-matches::
135--name-only::
136-L::
137--files-without-match::
Junio C Hamano617fdb82006-05-16 02:14:21138Instead of showing every matched line, show only the
139names of files that contain (or do not contain) matches.
Junio C Hamano636c8b22010-03-07 22:25:17140For better compatibility with 'git diff', `--name-only` is a
141synonym for `--files-with-matches`.
Junio C Hamano617fdb82006-05-16 02:14:21142
Junio C Hamano7d449522010-07-01 00:08:51143-O [<pager>]::
144--open-files-in-pager [<pager>]::
145Open the matching files in the pager (not the output of 'grep').
146If the pager happens to be "less" or "vi", and the user
147specified only one pattern, the first file is positioned at
148the first match automatically.
149
Junio C Hamanoa476efa2008-10-10 15:31:42150-z::
151--null::
152Output \0 instead of the character that normally follows a
153file name.
154
Junio C Hamanoeb415992008-06-08 22:49:47155-c::
156--count::
Junio C Hamano617fdb82006-05-16 02:14:21157Instead of showing every matched line, show the number of
158lines that match.
159
Junio C Hamano4aa0bcc2010-03-03 05:13:12160--color[=<when>]::
Junio C Hamanod257cff2009-03-18 05:27:16161Show colored matches.
Junio C Hamano4aa0bcc2010-03-03 05:13:12162The value must be always (the default), never, or auto.
Junio C Hamanod257cff2009-03-18 05:27:16163
164--no-color::
165Turn off match highlighting, even when the configuration file
166gives the default to color output.
Junio C Hamano4aa0bcc2010-03-03 05:13:12167Same as `--color=never`.
Junio C Hamanod257cff2009-03-18 05:27:16168
Junio C Hamano4c4b0122011-06-30 01:19:32169--break::
170Print an empty line between matches from different files.
171
172--heading::
173Show the filename above the matches in that file instead of
174at the start of each shown line.
175
Junio C Hamano48bc1ce2009-07-09 16:49:19176-p::
177--show-function::
178Show the preceding line that contains the function name of
179the match, unless the matching line is a function name itself.
180The name is determined in the same way as 'git diff' works out
181patch hunk headers (see 'Defining a custom hunk-header' in
182linkgit:gitattributes[5]).
183
Junio C Hamano9775d402011-08-11 22:27:20184-<num>::
185-C <num>::
186--context <num>::
187Show <num> leading and trailing lines, and place a line
188containing `--` between contiguous groups of matches.
189
190-A <num>::
191--after-context <num>::
192Show <num> trailing lines, and place a line containing
193`--` between contiguous groups of matches.
194
195-B <num>::
196--before-context <num>::
197Show <num> leading lines, and place a line containing
198`--` between contiguous groups of matches.
199
200-W::
201--function-context::
202Show the surrounding text from the previous line containing a
203function name up to the one before the next function name,
204effectively showing the whole function in which the match was
205found.
206
Junio C Hamano617fdb82006-05-16 02:14:21207-f <file>::
208Read patterns from <file>, one per line.
209
Junio C Hamano3901ffb2006-06-26 23:46:53210-e::
211The next parameter is the pattern. This option has to be
Junio C Hamano636c8b22010-03-07 22:25:17212used for patterns starting with `-` and should be used in
Junio C Hamano00442022006-08-03 00:29:36213scripts passing user input to grep. Multiple patterns are
214combined by 'or'.
215
Junio C Hamanoeb415992008-06-08 22:49:47216--and::
217--or::
218--not::
219( ... )::
Junio C Hamanof9771f62007-01-17 17:42:30220Specify how multiple patterns are combined using Boolean
Junio C Hamano00442022006-08-03 00:29:36221expressions. `--or` is the default operator. `--and` has
222higher precedence than `--or`. `-e` has to be used for all
223patterns.
Junio C Hamano3901ffb2006-06-26 23:46:53224
Junio C Hamanofbe00522006-10-19 05:58:48225--all-match::
226When giving multiple pattern expressions combined with `--or`,
227this flag is specified to limit the match to files that
228have lines to match all of them.
229
Junio C Hamano83b35472010-01-29 05:02:13230-q::
231--quiet::
232Do not output matched lines; instead, exit with status 0 when
233there is a match and with non-zero status when there isn't.
234
Junio C Hamano636c8b22010-03-07 22:25:17235<tree>...::
236Instead of searching tracked files in the working tree, search
237blobs in the given trees.
Junio C Hamano617fdb82006-05-16 02:14:21238
Junio C Hamano00442022006-08-03 00:29:36239\--::
Junio C Hamanoa6331a82006-01-22 07:50:33240Signals the end of options; the rest of the parameters
Junio C Hamano74a198f2010-02-22 00:13:31241are <pathspec> limiters.
Junio C Hamanoa6331a82006-01-22 07:50:33242
Junio C Hamano74a198f2010-02-22 00:13:31243<pathspec>...::
244If given, limit the search to paths matching at least one pattern.
245Both leading paths match and glob(7) patterns are supported.
Junio C Hamano1a4e8412005-12-27 08:17:23246
Junio C Hamano636c8b22010-03-07 22:25:17247Examples
248--------
Junio C Hamano00442022006-08-03 00:29:36249
Junio C Hamano16ebcd02011-08-05 00:05:45250`git grep {apostrophe}time_t{apostrophe} \-- {apostrophe}*.[ch]{apostrophe}`::
Junio C Hamano74a198f2010-02-22 00:13:31251Looks for `time_t` in all tracked .c and .h files in the working
252directory and its subdirectories.
253
Junio C Hamano16ebcd02011-08-05 00:05:45254`git grep -e {apostrophe}#define{apostrophe} --and \( -e MAX_PATH -e PATH_MAX \)`::
Junio C Hamano00442022006-08-03 00:29:36255Looks for a line that has `#define` and either `MAX_PATH` or
256`PATH_MAX`.
257
Junio C Hamano16ebcd02011-08-05 00:05:45258`git grep --all-match -e NODE -e Unexpected`::
Junio C Hamanofbe00522006-10-19 05:58:48259Looks for a line that has `NODE` or `Unexpected` in
260files that have lines that match both.
261
Junio C Hamano1a4e8412005-12-27 08:17:23262GIT
263---
Junio C Hamanof7c042d2008-06-06 22:50:53264Part of the linkgit:git[1] suite