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