blob: c5a5dad1ce27dde6c3846beaf7ab2f7aa8ed81c8 [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
78-l | --files-with-matches | -L | --files-without-match::
79Instead of showing every matched line, show only the
80names of files that contain (or do not contain) matches.
81
82-c | --count::
83Instead of showing every matched line, show the number of
84lines that match.
85
86-[ABC] <context>::
87Show `context` trailing (`A` -- after), or leading (`B`
88-- before), or both (`C` -- context) lines, and place a
Junio C Hamano341071d2006-06-04 07:24:4889line containing `--` between contiguous groups of
Junio C Hamano617fdb82006-05-16 02:14:2190matches.
91
Junio C Hamano9882a522007-04-27 08:22:2292-<num>::
93A shortcut for specifying -C<num>.
94
Junio C Hamano617fdb82006-05-16 02:14:2195-f <file>::
96Read patterns from <file>, one per line.
97
Junio C Hamano3901ffb2006-06-26 23:46:5398-e::
99The next parameter is the pattern. This option has to be
100used for patterns starting with - and should be used in
Junio C Hamano00442022006-08-03 00:29:36101scripts passing user input to grep. Multiple patterns are
102combined by 'or'.
103
104--and | --or | --not | ( | )::
Junio C Hamanof9771f62007-01-17 17:42:30105Specify how multiple patterns are combined using Boolean
Junio C Hamano00442022006-08-03 00:29:36106expressions. `--or` is the default operator. `--and` has
107higher precedence than `--or`. `-e` has to be used for all
108patterns.
Junio C Hamano3901ffb2006-06-26 23:46:53109
Junio C Hamanofbe00522006-10-19 05:58:48110--all-match::
111When giving multiple pattern expressions combined with `--or`,
112this flag is specified to limit the match to files that
113have lines to match all of them.
114
Junio C Hamano617fdb82006-05-16 02:14:21115`<tree>...`::
116Search blobs in the trees for specified patterns.
117
Junio C Hamano00442022006-08-03 00:29:36118\--::
Junio C Hamanoa6331a82006-01-22 07:50:33119Signals the end of options; the rest of the parameters
120are <path> limiters.
121
Junio C Hamano1a4e8412005-12-27 08:17:23122
Junio C Hamano00442022006-08-03 00:29:36123Example
124-------
125
126git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
127Looks for a line that has `#define` and either `MAX_PATH` or
128`PATH_MAX`.
129
Junio C Hamanofbe00522006-10-19 05:58:48130git grep --all-match -e NODE -e Unexpected::
131Looks for a line that has `NODE` or `Unexpected` in
132files that have lines that match both.
133
Junio C Hamano1a4e8412005-12-27 08:17:23134Author
135------
Junio C Hamano617fdb82006-05-16 02:14:21136Originally written by Linus Torvalds <torvalds@osdl.org>, later
137revamped by Junio C Hamano.
138
Junio C Hamano1a4e8412005-12-27 08:17:23139
140Documentation
141--------------
142Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
143
144GIT
145---
146Part of the gitlink:git[7] suite
147