blob: e44a4988b7a7ed7100da6e2ba098d7fda17a2f83 [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 Hamano617fdb82006-05-16 02:14:2123 [-A <post-context>] [-B <pre-context>] [-C <context>]
Junio C Hamano9882a522007-04-27 08:22:2224 [-f <file>] [-e] <pattern>
Junio C Hamano636c8b22010-03-07 22:25:1725 [--and|--or|--not|(|)|-e <pattern>...]
26 [--cached | --no-index | <tree>...]
Junio C Hamano74a198f2010-02-22 00:13:3127 [--] [<pathspec>...]
Junio C Hamano1a4e8412005-12-27 08:17:2328
29DESCRIPTION
30-----------
Junio C Hamano74a198f2010-02-22 00:13:3131Look for specified patterns in the tracked files in the work tree, blobs
32registered in the index file, or blobs in given tree objects.
Junio C Hamano1a4e8412005-12-27 08:17:2333
34
Junio C Hamanoa03ac862011-04-02 04:32:2935CONFIGURATION
36-------------
37
38grep.lineNumber::
39If set to true, enable '-n' option by default.
40
41grep.extendedRegexp::
42If set to true, enable '--extended-regexp' option by default.
43
44
Junio C Hamano1a4e8412005-12-27 08:17:2345OPTIONS
46-------
Junio C Hamano617fdb82006-05-16 02:14:2147--cached::
Junio C Hamano636c8b22010-03-07 22:25:1748Instead of searching tracked files in the working tree, search
49blobs registered in the index file.
50
51--no-index::
52Search files in the current directory, not just those tracked by git.
Junio C Hamano617fdb82006-05-16 02:14:2153
Junio C Hamanoeb415992008-06-08 22:49:4754-a::
55--text::
Junio C Hamano617fdb82006-05-16 02:14:2156Process binary files as if they were text.
57
Junio C Hamanoeb415992008-06-08 22:49:4758-i::
59--ignore-case::
Junio C Hamano617fdb82006-05-16 02:14:2160Ignore case differences between the patterns and the
61files.
62
Junio C Hamano9882a522007-04-27 08:22:2263-I::
64Don't match the pattern in binary files.
65
Junio C Hamano9f883862009-08-11 06:23:5266--max-depth <depth>::
Junio C Hamano74a198f2010-02-22 00:13:3167For each <pathspec> given on command line, descend at most <depth>
Junio C Hamano9f883862009-08-11 06:23:5268levels of directories. A negative value means no limit.
69
Junio C Hamanoeb415992008-06-08 22:49:4770-w::
71--word-regexp::
Junio C Hamano617fdb82006-05-16 02:14:2172Match the pattern only at word boundary (either begin at the
73beginning of a line, or preceded by a non-word character; end at
74the end of a line or followed by a non-word character).
75
Junio C Hamanoeb415992008-06-08 22:49:4776-v::
77--invert-match::
Junio C Hamano617fdb82006-05-16 02:14:2178Select non-matching lines.
79
Junio C Hamanoeb415992008-06-08 22:49:4780-h::
81-H::
Junio C Hamano97efb002006-09-16 18:16:0482By default, the command shows the filename for each
83match. `-h` option is used to suppress this output.
84`-H` is there for completeness and does not do anything
85except it overrides `-h` given earlier on the command
86line.
87
Junio C Hamano85e45fa2006-08-13 07:47:4188--full-name::
89When run from a subdirectory, the command usually
90outputs paths relative to the current directory. This
91option forces paths to be output relative to the project
92top directory.
93
Junio C Hamanoeb415992008-06-08 22:49:4794-E::
95--extended-regexp::
96-G::
97--basic-regexp::
Junio C Hamano617fdb82006-05-16 02:14:2198Use POSIX extended/basic regexp for patterns. Default
99is to use basic regexp.
100
Junio C Hamano084228c2011-05-30 08:13:52101-P::
102--perl-regexp::
103Use Perl-compatible regexp for patterns. Requires libpcre to be
104compiled in.
105
Junio C Hamanoeb415992008-06-08 22:49:47106-F::
107--fixed-strings::
Junio C Hamano9882a522007-04-27 08:22:22108Use fixed strings for patterns (don't interpret pattern
109as a regex).
110
Junio C Hamano617fdb82006-05-16 02:14:21111-n::
Junio C Hamano2906d342011-03-29 02:19:17112--line-number::
Junio C Hamano617fdb82006-05-16 02:14:21113Prefix the line number to matching lines.
114
Junio C Hamanoeb415992008-06-08 22:49:47115-l::
116--files-with-matches::
117--name-only::
118-L::
119--files-without-match::
Junio C Hamano617fdb82006-05-16 02:14:21120Instead of showing every matched line, show only the
121names of files that contain (or do not contain) matches.
Junio C Hamano636c8b22010-03-07 22:25:17122For better compatibility with 'git diff', `--name-only` is a
123synonym for `--files-with-matches`.
Junio C Hamano617fdb82006-05-16 02:14:21124
Junio C Hamano7d449522010-07-01 00:08:51125-O [<pager>]::
126--open-files-in-pager [<pager>]::
127Open the matching files in the pager (not the output of 'grep').
128If the pager happens to be "less" or "vi", and the user
129specified only one pattern, the first file is positioned at
130the first match automatically.
131
Junio C Hamanoa476efa2008-10-10 15:31:42132-z::
133--null::
134Output \0 instead of the character that normally follows a
135file name.
136
Junio C Hamanoeb415992008-06-08 22:49:47137-c::
138--count::
Junio C Hamano617fdb82006-05-16 02:14:21139Instead of showing every matched line, show the number of
140lines that match.
141
Junio C Hamano4aa0bcc2010-03-03 05:13:12142--color[=<when>]::
Junio C Hamanod257cff2009-03-18 05:27:16143Show colored matches.
Junio C Hamano4aa0bcc2010-03-03 05:13:12144The value must be always (the default), never, or auto.
Junio C Hamanod257cff2009-03-18 05:27:16145
146--no-color::
147Turn off match highlighting, even when the configuration file
148gives the default to color output.
Junio C Hamano4aa0bcc2010-03-03 05:13:12149Same as `--color=never`.
Junio C Hamanod257cff2009-03-18 05:27:16150
Junio C Hamano4c4b0122011-06-30 01:19:32151--break::
152Print an empty line between matches from different files.
153
154--heading::
155Show the filename above the matches in that file instead of
156at the start of each shown line.
157
Junio C Hamano48bc1ce2009-07-09 16:49:19158-p::
159--show-function::
160Show the preceding line that contains the function name of
161the match, unless the matching line is a function name itself.
162The name is determined in the same way as 'git diff' works out
163patch hunk headers (see 'Defining a custom hunk-header' in
164linkgit:gitattributes[5]).
165
Junio C Hamano9775d402011-08-11 22:27:20166-<num>::
167-C <num>::
168--context <num>::
169Show <num> leading and trailing lines, and place a line
170containing `--` between contiguous groups of matches.
171
172-A <num>::
173--after-context <num>::
174Show <num> trailing lines, and place a line containing
175`--` between contiguous groups of matches.
176
177-B <num>::
178--before-context <num>::
179Show <num> leading lines, and place a line containing
180`--` between contiguous groups of matches.
181
182-W::
183--function-context::
184Show the surrounding text from the previous line containing a
185function name up to the one before the next function name,
186effectively showing the whole function in which the match was
187found.
188
Junio C Hamano617fdb82006-05-16 02:14:21189-f <file>::
190Read patterns from <file>, one per line.
191
Junio C Hamano3901ffb2006-06-26 23:46:53192-e::
193The next parameter is the pattern. This option has to be
Junio C Hamano636c8b22010-03-07 22:25:17194used for patterns starting with `-` and should be used in
Junio C Hamano00442022006-08-03 00:29:36195scripts passing user input to grep. Multiple patterns are
196combined by 'or'.
197
Junio C Hamanoeb415992008-06-08 22:49:47198--and::
199--or::
200--not::
201( ... )::
Junio C Hamanof9771f62007-01-17 17:42:30202Specify how multiple patterns are combined using Boolean
Junio C Hamano00442022006-08-03 00:29:36203expressions. `--or` is the default operator. `--and` has
204higher precedence than `--or`. `-e` has to be used for all
205patterns.
Junio C Hamano3901ffb2006-06-26 23:46:53206
Junio C Hamanofbe00522006-10-19 05:58:48207--all-match::
208When giving multiple pattern expressions combined with `--or`,
209this flag is specified to limit the match to files that
210have lines to match all of them.
211
Junio C Hamano83b35472010-01-29 05:02:13212-q::
213--quiet::
214Do not output matched lines; instead, exit with status 0 when
215there is a match and with non-zero status when there isn't.
216
Junio C Hamano636c8b22010-03-07 22:25:17217<tree>...::
218Instead of searching tracked files in the working tree, search
219blobs in the given trees.
Junio C Hamano617fdb82006-05-16 02:14:21220
Junio C Hamano00442022006-08-03 00:29:36221\--::
Junio C Hamanoa6331a82006-01-22 07:50:33222Signals the end of options; the rest of the parameters
Junio C Hamano74a198f2010-02-22 00:13:31223are <pathspec> limiters.
Junio C Hamanoa6331a82006-01-22 07:50:33224
Junio C Hamano74a198f2010-02-22 00:13:31225<pathspec>...::
226If given, limit the search to paths matching at least one pattern.
227Both leading paths match and glob(7) patterns are supported.
Junio C Hamano1a4e8412005-12-27 08:17:23228
Junio C Hamano636c8b22010-03-07 22:25:17229Examples
230--------
Junio C Hamano00442022006-08-03 00:29:36231
Junio C Hamano16ebcd02011-08-05 00:05:45232`git grep {apostrophe}time_t{apostrophe} \-- {apostrophe}*.[ch]{apostrophe}`::
Junio C Hamano74a198f2010-02-22 00:13:31233Looks for `time_t` in all tracked .c and .h files in the working
234directory and its subdirectories.
235
Junio C Hamano16ebcd02011-08-05 00:05:45236`git grep -e {apostrophe}#define{apostrophe} --and \( -e MAX_PATH -e PATH_MAX \)`::
Junio C Hamano00442022006-08-03 00:29:36237Looks for a line that has `#define` and either `MAX_PATH` or
238`PATH_MAX`.
239
Junio C Hamano16ebcd02011-08-05 00:05:45240`git grep --all-match -e NODE -e Unexpected`::
Junio C Hamanofbe00522006-10-19 05:58:48241Looks for a line that has `NODE` or `Unexpected` in
242files that have lines that match both.
243
Junio C Hamano1a4e8412005-12-27 08:17:23244GIT
245---
Junio C Hamanof7c042d2008-06-06 22:50:53246Part of the linkgit:git[1] suite