blob: 1b646b73f069e72bc6faa3a058d61ace77c9934c [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
Junio C Hamanoeb415992008-06-08 22:49:4736-a::
37--text::
Junio C Hamano617fdb82006-05-16 02:14:2138Process binary files as if they were text.
39
Junio C Hamanoeb415992008-06-08 22:49:4740-i::
41--ignore-case::
Junio C Hamano617fdb82006-05-16 02:14:2142Ignore case differences between the patterns and the
43files.
44
Junio C Hamano9882a522007-04-27 08:22:2245-I::
46Don't match the pattern in binary files.
47
Junio C Hamanoeb415992008-06-08 22:49:4748-w::
49--word-regexp::
Junio C Hamano617fdb82006-05-16 02:14:2150Match the pattern only at word boundary (either begin at the
51beginning of a line, or preceded by a non-word character; end at
52the end of a line or followed by a non-word character).
53
Junio C Hamanoeb415992008-06-08 22:49:4754-v::
55--invert-match::
Junio C Hamano617fdb82006-05-16 02:14:2156Select non-matching lines.
57
Junio C Hamanoeb415992008-06-08 22:49:4758-h::
59-H::
Junio C Hamano97efb002006-09-16 18:16:0460By default, the command shows the filename for each
61match. `-h` option is used to suppress this output.
62`-H` is there for completeness and does not do anything
63except it overrides `-h` given earlier on the command
64line.
65
Junio C Hamano85e45fa2006-08-13 07:47:4166--full-name::
67When run from a subdirectory, the command usually
68outputs paths relative to the current directory. This
69option forces paths to be output relative to the project
70top directory.
71
Junio C Hamanoeb415992008-06-08 22:49:4772-E::
73--extended-regexp::
74-G::
75--basic-regexp::
Junio C Hamano617fdb82006-05-16 02:14:2176Use POSIX extended/basic regexp for patterns. Default
77is to use basic regexp.
78
Junio C Hamanoeb415992008-06-08 22:49:4779-F::
80--fixed-strings::
Junio C Hamano9882a522007-04-27 08:22:2281Use fixed strings for patterns (don't interpret pattern
82as a regex).
83
Junio C Hamano617fdb82006-05-16 02:14:2184-n::
85Prefix the line number to matching lines.
86
Junio C Hamanoeb415992008-06-08 22:49:4787-l::
88--files-with-matches::
89--name-only::
90-L::
91--files-without-match::
Junio C Hamano617fdb82006-05-16 02:14:2192Instead of showing every matched line, show only the
93names of files that contain (or do not contain) matches.
Junio C Hamano4f1d8c42008-03-03 02:01:1694For better compatibility with git-diff, --name-only is a
Junio C Hamano074766f2008-02-22 22:57:0695synonym for --files-with-matches.
Junio C Hamano617fdb82006-05-16 02:14:2196
Junio C Hamanoeb415992008-06-08 22:49:4797-c::
98--count::
Junio C Hamano617fdb82006-05-16 02:14:2199Instead of showing every matched line, show the number of
100lines that match.
101
102-[ABC] <context>::
103Show `context` trailing (`A` -- after), or leading (`B`
104-- before), or both (`C` -- context) lines, and place a
Junio C Hamano341071d2006-06-04 07:24:48105line containing `--` between contiguous groups of
Junio C Hamano617fdb82006-05-16 02:14:21106matches.
107
Junio C Hamano9882a522007-04-27 08:22:22108-<num>::
109A shortcut for specifying -C<num>.
110
Junio C Hamano617fdb82006-05-16 02:14:21111-f <file>::
112Read patterns from <file>, one per line.
113
Junio C Hamano3901ffb2006-06-26 23:46:53114-e::
115The next parameter is the pattern. This option has to be
116used for patterns starting with - and should be used in
Junio C Hamano00442022006-08-03 00:29:36117scripts passing user input to grep. Multiple patterns are
118combined by 'or'.
119
Junio C Hamanoeb415992008-06-08 22:49:47120--and::
121--or::
122--not::
123( ... )::
Junio C Hamanof9771f62007-01-17 17:42:30124Specify how multiple patterns are combined using Boolean
Junio C Hamano00442022006-08-03 00:29:36125expressions. `--or` is the default operator. `--and` has
126higher precedence than `--or`. `-e` has to be used for all
127patterns.
Junio C Hamano3901ffb2006-06-26 23:46:53128
Junio C Hamanofbe00522006-10-19 05:58:48129--all-match::
130When giving multiple pattern expressions combined with `--or`,
131this flag is specified to limit the match to files that
132have lines to match all of them.
133
Junio C Hamano617fdb82006-05-16 02:14:21134`<tree>...`::
135Search blobs in the trees for specified patterns.
136
Junio C Hamano00442022006-08-03 00:29:36137\--::
Junio C Hamanoa6331a82006-01-22 07:50:33138Signals the end of options; the rest of the parameters
139are <path> limiters.
140
Junio C Hamano1a4e8412005-12-27 08:17:23141
Junio C Hamano00442022006-08-03 00:29:36142Example
143-------
144
145git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
146Looks for a line that has `#define` and either `MAX_PATH` or
147`PATH_MAX`.
148
Junio C Hamanofbe00522006-10-19 05:58:48149git grep --all-match -e NODE -e Unexpected::
150Looks for a line that has `NODE` or `Unexpected` in
151files that have lines that match both.
152
Junio C Hamano1a4e8412005-12-27 08:17:23153Author
154------
Junio C Hamano617fdb82006-05-16 02:14:21155Originally written by Linus Torvalds <torvalds@osdl.org>, later
156revamped by Junio C Hamano.
157
Junio C Hamano1a4e8412005-12-27 08:17:23158
159Documentation
160--------------
161Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
162
163GIT
164---
Junio C Hamanof7c042d2008-06-06 22:50:53165Part of the linkgit:git[1] suite