]>
Commit | Line | Data |
---|---|---|
2aba319a JH |
1 | git-grep(1) |
2 | =========== | |
2aba319a JH |
3 | |
4 | NAME | |
5 | ---- | |
5001422d | 6 | git-grep - Print lines matching a pattern |
2aba319a JH |
7 | |
8 | ||
9 | SYNOPSIS | |
10 | -------- | |
1c57119c | 11 | [verse] |
ec2537be | 12 | 'git grep' [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp] |
17fd965d | 13 | [-v | --invert-match] [-h|-H] [--full-name] |
cf0d720b AR |
14 | [-E | --extended-regexp] [-G | --basic-regexp] |
15 | [-F | --fixed-strings] [-n] | |
16 | [-l | --files-with-matches] [-L | --files-without-match] | |
83caecca | 17 | [-z | --null] |
4ff61c21 | 18 | [-c | --count] [--all-match] [-q | --quiet] |
a91f453f | 19 | [--max-depth <depth>] |
73e9da01 | 20 | [--color[=<when>] | --no-color] |
1c57119c | 21 | [-A <post-context>] [-B <pre-context>] [-C <context>] |
cf0d720b | 22 | [-f <file>] [-e] <pattern> |
ec2537be | 23 | [--and|--or|--not|(|)|-e <pattern>...] |
2e48fcdb | 24 | [--cached | --no-index | <tree>...] |
3ac44408 | 25 | [--] [<pathspec>...] |
2aba319a JH |
26 | |
27 | DESCRIPTION | |
28 | ----------- | |
3ac44408 ML |
29 | Look for specified patterns in the tracked files in the work tree, blobs |
30 | registered in the index file, or blobs in given tree objects. | |
2aba319a JH |
31 | |
32 | ||
33 | OPTIONS | |
34 | ------- | |
1c57119c | 35 | --cached:: |
2e48fcdb ML |
36 | Instead of searching tracked files in the working tree, search |
37 | blobs registered in the index file. | |
38 | ||
39 | --no-index:: | |
40 | Search files in the current directory, not just those tracked by git. | |
1c57119c | 41 | |
3240240f SB |
42 | -a:: |
43 | --text:: | |
1c57119c JH |
44 | Process binary files as if they were text. |
45 | ||
3240240f SB |
46 | -i:: |
47 | --ignore-case:: | |
1c57119c JH |
48 | Ignore case differences between the patterns and the |
49 | files. | |
50 | ||
cf0d720b AR |
51 | -I:: |
52 | Don't match the pattern in binary files. | |
53 | ||
a91f453f | 54 | --max-depth <depth>:: |
3ac44408 | 55 | For each <pathspec> given on command line, descend at most <depth> |
a91f453f MK |
56 | levels of directories. A negative value means no limit. |
57 | ||
3240240f SB |
58 | -w:: |
59 | --word-regexp:: | |
1c57119c JH |
60 | Match the pattern only at word boundary (either begin at the |
61 | beginning of a line, or preceded by a non-word character; end at | |
62 | the end of a line or followed by a non-word character). | |
63 | ||
3240240f SB |
64 | -v:: |
65 | --invert-match:: | |
1c57119c JH |
66 | Select non-matching lines. |
67 | ||
3240240f SB |
68 | -h:: |
69 | -H:: | |
17fd965d JH |
70 | By default, the command shows the filename for each |
71 | match. `-h` option is used to suppress this output. | |
72 | `-H` is there for completeness and does not do anything | |
73 | except it overrides `-h` given earlier on the command | |
74 | line. | |
75 | ||
0d042fec JH |
76 | --full-name:: |
77 | When run from a subdirectory, the command usually | |
78 | outputs paths relative to the current directory. This | |
79 | option forces paths to be output relative to the project | |
80 | top directory. | |
81 | ||
3240240f SB |
82 | -E:: |
83 | --extended-regexp:: | |
84 | -G:: | |
85 | --basic-regexp:: | |
1c57119c JH |
86 | Use POSIX extended/basic regexp for patterns. Default |
87 | is to use basic regexp. | |
5b2bcc7b | 88 | |
3240240f SB |
89 | -F:: |
90 | --fixed-strings:: | |
cf0d720b AR |
91 | Use fixed strings for patterns (don't interpret pattern |
92 | as a regex). | |
93 | ||
1c57119c JH |
94 | -n:: |
95 | Prefix the line number to matching lines. | |
2aba319a | 96 | |
3240240f SB |
97 | -l:: |
98 | --files-with-matches:: | |
99 | --name-only:: | |
100 | -L:: | |
101 | --files-without-match:: | |
1c57119c JH |
102 | Instead of showing every matched line, show only the |
103 | names of files that contain (or do not contain) matches. | |
bfb8306d ML |
104 | For better compatibility with 'git diff', `--name-only` is a |
105 | synonym for `--files-with-matches`. | |
2aba319a | 106 | |
83caecca RZ |
107 | -z:: |
108 | --null:: | |
109 | Output \0 instead of the character that normally follows a | |
110 | file name. | |
111 | ||
3240240f SB |
112 | -c:: |
113 | --count:: | |
1c57119c JH |
114 | Instead of showing every matched line, show the number of |
115 | lines that match. | |
116 | ||
73e9da01 | 117 | --color[=<when>]:: |
7e8f59d5 | 118 | Show colored matches. |
73e9da01 | 119 | The value must be always (the default), never, or auto. |
7e8f59d5 RS |
120 | |
121 | --no-color:: | |
122 | Turn off match highlighting, even when the configuration file | |
123 | gives the default to color output. | |
73e9da01 | 124 | Same as `--color=never`. |
7e8f59d5 | 125 | |
1c57119c JH |
126 | -[ABC] <context>:: |
127 | Show `context` trailing (`A` -- after), or leading (`B` | |
128 | -- before), or both (`C` -- context) lines, and place a | |
abda1ef5 | 129 | line containing `--` between contiguous groups of |
1c57119c JH |
130 | matches. |
131 | ||
cf0d720b | 132 | -<num>:: |
bfb8306d | 133 | A shortcut for specifying `-C<num>`. |
cf0d720b | 134 | |
2944e4e6 RS |
135 | -p:: |
136 | --show-function:: | |
137 | Show the preceding line that contains the function name of | |
138 | the match, unless the matching line is a function name itself. | |
60ecac98 RS |
139 | The name is determined in the same way as 'git diff' works out |
140 | patch hunk headers (see 'Defining a custom hunk-header' in | |
141 | linkgit:gitattributes[5]). | |
2944e4e6 | 142 | |
1c57119c JH |
143 | -f <file>:: |
144 | Read patterns from <file>, one per line. | |
145 | ||
3acb27b6 ML |
146 | -e:: |
147 | The next parameter is the pattern. This option has to be | |
bfb8306d | 148 | used for patterns starting with `-` and should be used in |
fba0cbd9 ML |
149 | scripts passing user input to grep. Multiple patterns are |
150 | combined by 'or'. | |
151 | ||
3240240f SB |
152 | --and:: |
153 | --or:: | |
154 | --not:: | |
155 | ( ... ):: | |
23bfbb81 | 156 | Specify how multiple patterns are combined using Boolean |
fba0cbd9 ML |
157 | expressions. `--or` is the default operator. `--and` has |
158 | higher precedence than `--or`. `-e` has to be used for all | |
159 | patterns. | |
3acb27b6 | 160 | |
0ab7befa JH |
161 | --all-match:: |
162 | When giving multiple pattern expressions combined with `--or`, | |
163 | this flag is specified to limit the match to files that | |
164 | have lines to match all of them. | |
165 | ||
4ff61c21 JH |
166 | -q:: |
167 | --quiet:: | |
168 | Do not output matched lines; instead, exit with status 0 when | |
169 | there is a match and with non-zero status when there isn't. | |
170 | ||
bfb8306d | 171 | <tree>...:: |
2e48fcdb ML |
172 | Instead of searching tracked files in the working tree, search |
173 | blobs in the given trees. | |
1c57119c | 174 | |
fba0cbd9 | 175 | \--:: |
1c57119c | 176 | Signals the end of options; the rest of the parameters |
3ac44408 | 177 | are <pathspec> limiters. |
2aba319a | 178 | |
3ac44408 ML |
179 | <pathspec>...:: |
180 | If given, limit the search to paths matching at least one pattern. | |
181 | Both leading paths match and glob(7) patterns are supported. | |
2aba319a | 182 | |
04416018 ML |
183 | Examples |
184 | -------- | |
fba0cbd9 | 185 | |
3ac44408 ML |
186 | git grep 'time_t' -- '*.[ch]':: |
187 | Looks for `time_t` in all tracked .c and .h files in the working | |
188 | directory and its subdirectories. | |
189 | ||
fba0cbd9 ML |
190 | git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \):: |
191 | Looks for a line that has `#define` and either `MAX_PATH` or | |
192 | `PATH_MAX`. | |
193 | ||
0ab7befa JH |
194 | git grep --all-match -e NODE -e Unexpected:: |
195 | Looks for a line that has `NODE` or `Unexpected` in | |
196 | files that have lines that match both. | |
197 | ||
2aba319a JH |
198 | Author |
199 | ------ | |
1c57119c JH |
200 | Originally written by Linus Torvalds <torvalds@osdl.org>, later |
201 | revamped by Junio C Hamano. | |
202 | ||
2aba319a JH |
203 | |
204 | Documentation | |
205 | -------------- | |
206 | Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. | |
207 | ||
208 | GIT | |
209 | --- | |
9e1f0a85 | 210 | Part of the linkgit:git[1] suite |