blob: 553da6cbb1777a94cb3d6b48dc77c445e18ca2b0 [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 Hamanofbe00522006-10-19 05:58:4819 [-c | --count] [--all-match]
Junio C Hamano617fdb82006-05-16 02:14:2120 [-A <post-context>] [-B <pre-context>] [-C <context>]
Junio C Hamano9882a522007-04-27 08:22:2221 [-f <file>] [-e] <pattern>
22 [--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
Junio C Hamano617fdb82006-05-16 02:14:2123 [--] [<path>...]
Junio C Hamano1a4e8412005-12-27 08:17:2324
25DESCRIPTION
26-----------
Junio C Hamano617fdb82006-05-16 02:14:2127Look for specified patterns in the working tree files, blobs
28registered in the index file, or given tree objects.
Junio C Hamano1a4e8412005-12-27 08:17:2329
30
31OPTIONS
32-------
Junio C Hamano617fdb82006-05-16 02:14:2133--cached::
34Instead of searching in the working tree files, check
Junio C Hamano341071d2006-06-04 07:24:4835the blobs registered in the index file.
Junio C Hamano617fdb82006-05-16 02:14:2136
Junio C Hamanoeb415992008-06-08 22:49:4737-a::
38--text::
Junio C Hamano617fdb82006-05-16 02:14:2139Process binary files as if they were text.
40
Junio C Hamanoeb415992008-06-08 22:49:4741-i::
42--ignore-case::
Junio C Hamano617fdb82006-05-16 02:14:2143Ignore case differences between the patterns and the
44files.
45
Junio C Hamano9882a522007-04-27 08:22:2246-I::
47Don't match the pattern in binary files.
48
Junio C Hamanoeb415992008-06-08 22:49:4749-w::
50--word-regexp::
Junio C Hamano617fdb82006-05-16 02:14:2151Match the pattern only at word boundary (either begin at the
52beginning of a line, or preceded by a non-word character; end at
53the end of a line or followed by a non-word character).
54
Junio C Hamanoeb415992008-06-08 22:49:4755-v::
56--invert-match::
Junio C Hamano617fdb82006-05-16 02:14:2157Select non-matching lines.
58
Junio C Hamanoeb415992008-06-08 22:49:4759-h::
60-H::
Junio C Hamano97efb002006-09-16 18:16:0461By default, the command shows the filename for each
62match. `-h` option is used to suppress this output.
63`-H` is there for completeness and does not do anything
64except it overrides `-h` given earlier on the command
65line.
66
Junio C Hamano85e45fa2006-08-13 07:47:4167--full-name::
68When run from a subdirectory, the command usually
69outputs paths relative to the current directory. This
70option forces paths to be output relative to the project
71top directory.
72
Junio C Hamanoeb415992008-06-08 22:49:4773-E::
74--extended-regexp::
75-G::
76--basic-regexp::
Junio C Hamano617fdb82006-05-16 02:14:2177Use POSIX extended/basic regexp for patterns. Default
78is to use basic regexp.
79
Junio C Hamanoeb415992008-06-08 22:49:4780-F::
81--fixed-strings::
Junio C Hamano9882a522007-04-27 08:22:2282Use fixed strings for patterns (don't interpret pattern
83as a regex).
84
Junio C Hamano617fdb82006-05-16 02:14:2185-n::
86Prefix the line number to matching lines.
87
Junio C Hamanoeb415992008-06-08 22:49:4788-l::
89--files-with-matches::
90--name-only::
91-L::
92--files-without-match::
Junio C Hamano617fdb82006-05-16 02:14:2193Instead of showing every matched line, show only the
94names of files that contain (or do not contain) matches.
Junio C Hamanoba4b9282008-07-06 05:20:3195For better compatibility with 'git-diff', --name-only is a
Junio C Hamano074766f2008-02-22 22:57:0696synonym for --files-with-matches.
Junio C Hamano617fdb82006-05-16 02:14:2197
Junio C Hamanoa476efa2008-10-10 15:31:4298-z::
99--null::
100Output \0 instead of the character that normally follows a
101file name.
102
Junio C Hamanoeb415992008-06-08 22:49:47103-c::
104--count::
Junio C Hamano617fdb82006-05-16 02:14:21105Instead of showing every matched line, show the number of
106lines that match.
107
108-[ABC] <context>::
109Show `context` trailing (`A` -- after), or leading (`B`
110-- before), or both (`C` -- context) lines, and place a
Junio C Hamano341071d2006-06-04 07:24:48111line containing `--` between contiguous groups of
Junio C Hamano617fdb82006-05-16 02:14:21112matches.
113
Junio C Hamano9882a522007-04-27 08:22:22114-<num>::
115A shortcut for specifying -C<num>.
116
Junio C Hamano617fdb82006-05-16 02:14:21117-f <file>::
118Read patterns from <file>, one per line.
119
Junio C Hamano3901ffb2006-06-26 23:46:53120-e::
121The next parameter is the pattern. This option has to be
122used for patterns starting with - and should be used in
Junio C Hamano00442022006-08-03 00:29:36123scripts passing user input to grep. Multiple patterns are
124combined by 'or'.
125
Junio C Hamanoeb415992008-06-08 22:49:47126--and::
127--or::
128--not::
129( ... )::
Junio C Hamanof9771f62007-01-17 17:42:30130Specify how multiple patterns are combined using Boolean
Junio C Hamano00442022006-08-03 00:29:36131expressions. `--or` is the default operator. `--and` has
132higher precedence than `--or`. `-e` has to be used for all
133patterns.
Junio C Hamano3901ffb2006-06-26 23:46:53134
Junio C Hamanofbe00522006-10-19 05:58:48135--all-match::
136When giving multiple pattern expressions combined with `--or`,
137this flag is specified to limit the match to files that
138have lines to match all of them.
139
Junio C Hamano617fdb82006-05-16 02:14:21140`<tree>...`::
141Search blobs in the trees for specified patterns.
142
Junio C Hamano00442022006-08-03 00:29:36143\--::
Junio C Hamanoa6331a82006-01-22 07:50:33144Signals the end of options; the rest of the parameters
145are <path> limiters.
146
Junio C Hamano1a4e8412005-12-27 08:17:23147
Junio C Hamano00442022006-08-03 00:29:36148Example
149-------
150
151git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
152Looks for a line that has `#define` and either `MAX_PATH` or
153`PATH_MAX`.
154
Junio C Hamanofbe00522006-10-19 05:58:48155git grep --all-match -e NODE -e Unexpected::
156Looks for a line that has `NODE` or `Unexpected` in
157files that have lines that match both.
158
Junio C Hamano1a4e8412005-12-27 08:17:23159Author
160------
Junio C Hamano617fdb82006-05-16 02:14:21161Originally written by Linus Torvalds <torvalds@osdl.org>, later
162revamped by Junio C Hamano.
163
Junio C Hamano1a4e8412005-12-27 08:17:23164
165Documentation
166--------------
167Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
168
169GIT
170---
Junio C Hamanof7c042d2008-06-06 22:50:53171Part of the linkgit:git[1] suite