blob: c44724d03a60640d34963f068149a3fe6803d20e [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 Hamanofce7c7e2008-07-02 03:06:3812'git grep' [--cached]
Junio C Hamano617fdb82006-05-16 02:14:2113 [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
Junio C Hamano97efb002006-09-16 18:16:0414 [-v | --invert-match] [-h|-H] [--full-name]
Junio C Hamano9882a522007-04-27 08:22:2215 [-E | --extended-regexp] [-G | --basic-regexp]
16 [-F | --fixed-strings] [-n]
17 [-l | --files-with-matches] [-L | --files-without-match]
Junio C Hamanoa476efa2008-10-10 15:31:4218 [-z | --null]
Junio C Hamano83b35472010-01-29 05:02:1319 [-c | --count] [--all-match] [-q | --quiet]
Junio C Hamano9f883862009-08-11 06:23:5220 [--max-depth <depth>]
Junio C Hamanod257cff2009-03-18 05:27:1621 [--color | --no-color]
Junio C Hamano617fdb82006-05-16 02:14:2122 [-A <post-context>] [-B <pre-context>] [-C <context>]
Junio C Hamano9882a522007-04-27 08:22:2223 [-f <file>] [-e] <pattern>
24 [--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
Junio C Hamano74a198f2010-02-22 00:13:3125 [--] [<pathspec>...]
Junio C Hamano1a4e8412005-12-27 08:17:2326
27DESCRIPTION
28-----------
Junio C Hamano74a198f2010-02-22 00:13:3129Look for specified patterns in the tracked files in the work tree, blobs
30registered in the index file, or blobs in given tree objects.
Junio C Hamano1a4e8412005-12-27 08:17:2331
32
33OPTIONS
34-------
Junio C Hamano617fdb82006-05-16 02:14:2135--cached::
36Instead of searching in the working tree files, check
Junio C Hamano341071d2006-06-04 07:24:4837the blobs registered in the index file.
Junio C Hamano617fdb82006-05-16 02:14:2138
Junio C Hamanoeb415992008-06-08 22:49:4739-a::
40--text::
Junio C Hamano617fdb82006-05-16 02:14:2141Process binary files as if they were text.
42
Junio C Hamanoeb415992008-06-08 22:49:4743-i::
44--ignore-case::
Junio C Hamano617fdb82006-05-16 02:14:2145Ignore case differences between the patterns and the
46files.
47
Junio C Hamano9882a522007-04-27 08:22:2248-I::
49Don't match the pattern in binary files.
50
Junio C Hamano9f883862009-08-11 06:23:5251--max-depth <depth>::
Junio C Hamano74a198f2010-02-22 00:13:3152For each <pathspec> given on command line, descend at most <depth>
Junio C Hamano9f883862009-08-11 06:23:5253levels of directories. A negative value means no limit.
54
Junio C Hamanoeb415992008-06-08 22:49:4755-w::
56--word-regexp::
Junio C Hamano617fdb82006-05-16 02:14:2157Match the pattern only at word boundary (either begin at the
58beginning of a line, or preceded by a non-word character; end at
59the end of a line or followed by a non-word character).
60
Junio C Hamanoeb415992008-06-08 22:49:4761-v::
62--invert-match::
Junio C Hamano617fdb82006-05-16 02:14:2163Select non-matching lines.
64
Junio C Hamanoeb415992008-06-08 22:49:4765-h::
66-H::
Junio C Hamano97efb002006-09-16 18:16:0467By default, the command shows the filename for each
68match. `-h` option is used to suppress this output.
69`-H` is there for completeness and does not do anything
70except it overrides `-h` given earlier on the command
71line.
72
Junio C Hamano85e45fa2006-08-13 07:47:4173--full-name::
74When run from a subdirectory, the command usually
75outputs paths relative to the current directory. This
76option forces paths to be output relative to the project
77top directory.
78
Junio C Hamanoeb415992008-06-08 22:49:4779-E::
80--extended-regexp::
81-G::
82--basic-regexp::
Junio C Hamano617fdb82006-05-16 02:14:2183Use POSIX extended/basic regexp for patterns. Default
84is to use basic regexp.
85
Junio C Hamanoeb415992008-06-08 22:49:4786-F::
87--fixed-strings::
Junio C Hamano9882a522007-04-27 08:22:2288Use fixed strings for patterns (don't interpret pattern
89as a regex).
90
Junio C Hamano617fdb82006-05-16 02:14:2191-n::
92Prefix the line number to matching lines.
93
Junio C Hamanoeb415992008-06-08 22:49:4794-l::
95--files-with-matches::
96--name-only::
97-L::
98--files-without-match::
Junio C Hamano617fdb82006-05-16 02:14:2199Instead of showing every matched line, show only the
100names of files that contain (or do not contain) matches.
Junio C Hamano1aa40d22010-01-21 17:46:43101For better compatibility with 'git diff', --name-only is a
Junio C Hamano074766f2008-02-22 22:57:06102synonym for --files-with-matches.
Junio C Hamano617fdb82006-05-16 02:14:21103
Junio C Hamanoa476efa2008-10-10 15:31:42104-z::
105--null::
106Output \0 instead of the character that normally follows a
107file name.
108
Junio C Hamanoeb415992008-06-08 22:49:47109-c::
110--count::
Junio C Hamano617fdb82006-05-16 02:14:21111Instead of showing every matched line, show the number of
112lines that match.
113
Junio C Hamanod257cff2009-03-18 05:27:16114--color::
115Show colored matches.
116
117--no-color::
118Turn off match highlighting, even when the configuration file
119gives the default to color output.
120
Junio C Hamano617fdb82006-05-16 02:14:21121-[ABC] <context>::
122Show `context` trailing (`A` -- after), or leading (`B`
123-- before), or both (`C` -- context) lines, and place a
Junio C Hamano341071d2006-06-04 07:24:48124line containing `--` between contiguous groups of
Junio C Hamano617fdb82006-05-16 02:14:21125matches.
126
Junio C Hamano9882a522007-04-27 08:22:22127-<num>::
128A shortcut for specifying -C<num>.
129
Junio C Hamano48bc1ce2009-07-09 16:49:19130-p::
131--show-function::
132Show the preceding line that contains the function name of
133the match, unless the matching line is a function name itself.
134The name is determined in the same way as 'git diff' works out
135patch hunk headers (see 'Defining a custom hunk-header' in
136linkgit:gitattributes[5]).
137
Junio C Hamano617fdb82006-05-16 02:14:21138-f <file>::
139Read patterns from <file>, one per line.
140
Junio C Hamano3901ffb2006-06-26 23:46:53141-e::
142The next parameter is the pattern. This option has to be
143used for patterns starting with - and should be used in
Junio C Hamano00442022006-08-03 00:29:36144scripts passing user input to grep. Multiple patterns are
145combined by 'or'.
146
Junio C Hamanoeb415992008-06-08 22:49:47147--and::
148--or::
149--not::
150( ... )::
Junio C Hamanof9771f62007-01-17 17:42:30151Specify how multiple patterns are combined using Boolean
Junio C Hamano00442022006-08-03 00:29:36152expressions. `--or` is the default operator. `--and` has
153higher precedence than `--or`. `-e` has to be used for all
154patterns.
Junio C Hamano3901ffb2006-06-26 23:46:53155
Junio C Hamanofbe00522006-10-19 05:58:48156--all-match::
157When giving multiple pattern expressions combined with `--or`,
158this flag is specified to limit the match to files that
159have lines to match all of them.
160
Junio C Hamano83b35472010-01-29 05:02:13161-q::
162--quiet::
163Do not output matched lines; instead, exit with status 0 when
164there is a match and with non-zero status when there isn't.
165
Junio C Hamano617fdb82006-05-16 02:14:21166`<tree>...`::
167Search blobs in the trees for specified patterns.
168
Junio C Hamano00442022006-08-03 00:29:36169\--::
Junio C Hamanoa6331a82006-01-22 07:50:33170Signals the end of options; the rest of the parameters
Junio C Hamano74a198f2010-02-22 00:13:31171are <pathspec> limiters.
Junio C Hamanoa6331a82006-01-22 07:50:33172
Junio C Hamano74a198f2010-02-22 00:13:31173<pathspec>...::
174If given, limit the search to paths matching at least one pattern.
175Both leading paths match and glob(7) patterns are supported.
Junio C Hamano1a4e8412005-12-27 08:17:23176
Junio C Hamano00442022006-08-03 00:29:36177Example
178-------
179
Junio C Hamano74a198f2010-02-22 00:13:31180git grep 'time_t' -- '*.[ch]'::
181Looks for `time_t` in all tracked .c and .h files in the working
182directory and its subdirectories.
183
Junio C Hamano00442022006-08-03 00:29:36184git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
185Looks for a line that has `#define` and either `MAX_PATH` or
186`PATH_MAX`.
187
Junio C Hamanofbe00522006-10-19 05:58:48188git grep --all-match -e NODE -e Unexpected::
189Looks for a line that has `NODE` or `Unexpected` in
190files that have lines that match both.
191
Junio C Hamano1a4e8412005-12-27 08:17:23192Author
193------
Junio C Hamano617fdb82006-05-16 02:14:21194Originally written by Linus Torvalds <torvalds@osdl.org>, later
195revamped by Junio C Hamano.
196
Junio C Hamano1a4e8412005-12-27 08:17:23197
198Documentation
199--------------
200Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
201
202GIT
203---
Junio C Hamanof7c042d2008-06-06 22:50:53204Part of the linkgit:git[1] suite