blob: 71a73354f8cfa960f641d9563ee8af405b4f881f [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]
12'git-grep' [--cached]
13 [-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 Hamanofbe00522006-10-19 05:58:4818 [-c | --count] [--all-match]
Junio C Hamano617fdb82006-05-16 02:14:2119 [-A <post-context>] [-B <pre-context>] [-C <context>]
Junio C Hamano9882a522007-04-27 08:22:2220 [-f <file>] [-e] <pattern>
21 [--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
Junio C Hamano617fdb82006-05-16 02:14:2122 [--] [<path>...]
Junio C Hamano1a4e8412005-12-27 08:17:2323
24DESCRIPTION
25-----------
Junio C Hamano617fdb82006-05-16 02:14:2126Look for specified patterns in the working tree files, blobs
27registered in the index file, or given tree objects.
Junio C Hamano1a4e8412005-12-27 08:17:2328
29
30OPTIONS
31-------
Junio C Hamano617fdb82006-05-16 02:14:2132--cached::
33Instead of searching in the working tree files, check
Junio C Hamano341071d2006-06-04 07:24:4834the blobs registered in the index file.
Junio C Hamano617fdb82006-05-16 02:14:2135
36-a | --text::
37Process binary files as if they were text.
38
39-i | --ignore-case::
40Ignore case differences between the patterns and the
41files.
42
Junio C Hamano9882a522007-04-27 08:22:2243-I::
44Don't match the pattern in binary files.
45
Junio C Hamano617fdb82006-05-16 02:14:2146-w | --word-regexp::
47Match the pattern only at word boundary (either begin at the
48beginning of a line, or preceded by a non-word character; end at
49the end of a line or followed by a non-word character).
50
51-v | --invert-match::
52Select non-matching lines.
53
Junio C Hamano97efb002006-09-16 18:16:0454-h | -H::
55By default, the command shows the filename for each
56match. `-h` option is used to suppress this output.
57`-H` is there for completeness and does not do anything
58except it overrides `-h` given earlier on the command
59line.
60
Junio C Hamano85e45fa2006-08-13 07:47:4161--full-name::
62When run from a subdirectory, the command usually
63outputs paths relative to the current directory. This
64option forces paths to be output relative to the project
65top directory.
66
Junio C Hamano617fdb82006-05-16 02:14:2167-E | --extended-regexp | -G | --basic-regexp::
68Use POSIX extended/basic regexp for patterns. Default
69is to use basic regexp.
70
Junio C Hamano9882a522007-04-27 08:22:2271-F | --fixed-strings::
72Use fixed strings for patterns (don't interpret pattern
73as a regex).
74
Junio C Hamano617fdb82006-05-16 02:14:2175-n::
76Prefix the line number to matching lines.
77
Junio C Hamano074766f2008-02-22 22:57:0678-l | --files-with-matches | --name-only | -L | --files-without-match::
Junio C Hamano617fdb82006-05-16 02:14:2179Instead of showing every matched line, show only the
80names of files that contain (or do not contain) matches.
Junio C Hamano074766f2008-02-22 22:57:0681For better compatability with git-diff, --name-only is a
82synonym for --files-with-matches.
Junio C Hamano617fdb82006-05-16 02:14:2183
84-c | --count::
85Instead of showing every matched line, show the number of
86lines that match.
87
88-[ABC] <context>::
89Show `context` trailing (`A` -- after), or leading (`B`
90-- before), or both (`C` -- context) lines, and place a
Junio C Hamano341071d2006-06-04 07:24:4891line containing `--` between contiguous groups of
Junio C Hamano617fdb82006-05-16 02:14:2192matches.
93
Junio C Hamano9882a522007-04-27 08:22:2294-<num>::
95A shortcut for specifying -C<num>.
96
Junio C Hamano617fdb82006-05-16 02:14:2197-f <file>::
98Read patterns from <file>, one per line.
99
Junio C Hamano3901ffb2006-06-26 23:46:53100-e::
101The next parameter is the pattern. This option has to be
102used for patterns starting with - and should be used in
Junio C Hamano00442022006-08-03 00:29:36103scripts passing user input to grep. Multiple patterns are
104combined by 'or'.
105
106--and | --or | --not | ( | )::
Junio C Hamanof9771f62007-01-17 17:42:30107Specify how multiple patterns are combined using Boolean
Junio C Hamano00442022006-08-03 00:29:36108expressions. `--or` is the default operator. `--and` has
109higher precedence than `--or`. `-e` has to be used for all
110patterns.
Junio C Hamano3901ffb2006-06-26 23:46:53111
Junio C Hamanofbe00522006-10-19 05:58:48112--all-match::
113When giving multiple pattern expressions combined with `--or`,
114this flag is specified to limit the match to files that
115have lines to match all of them.
116
Junio C Hamano617fdb82006-05-16 02:14:21117`<tree>...`::
118Search blobs in the trees for specified patterns.
119
Junio C Hamano00442022006-08-03 00:29:36120\--::
Junio C Hamanoa6331a82006-01-22 07:50:33121Signals the end of options; the rest of the parameters
122are <path> limiters.
123
Junio C Hamano1a4e8412005-12-27 08:17:23124
Junio C Hamano00442022006-08-03 00:29:36125Example
126-------
127
128git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
129Looks for a line that has `#define` and either `MAX_PATH` or
130`PATH_MAX`.
131
Junio C Hamanofbe00522006-10-19 05:58:48132git grep --all-match -e NODE -e Unexpected::
133Looks for a line that has `NODE` or `Unexpected` in
134files that have lines that match both.
135
Junio C Hamano1a4e8412005-12-27 08:17:23136Author
137------
Junio C Hamano617fdb82006-05-16 02:14:21138Originally written by Linus Torvalds <torvalds@osdl.org>, later
139revamped by Junio C Hamano.
140
Junio C Hamano1a4e8412005-12-27 08:17:23141
142Documentation
143--------------
144Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
145
146GIT
147---
Junio C Hamano35738e82008-01-07 07:55:46148Part of the linkgit:git[7] suite