updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-grep.xml
blob367956032aff9534f64e149fd2a39a752dbff0a9
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-grep(1)">\r
5 <articleinfo>\r
6     <title>git-grep(1)</title>\r
7 <indexterm>\r
8 <primary>git-grep(1)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-grep - Print lines matching a pattern</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git grep</emphasis> [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]\r
19            [-v | --invert-match] [-h|-H] [--full-name]\r
20            [-E | --extended-regexp] [-G | --basic-regexp]\r
21            [-P | --perl-regexp]\r
22            [-F | --fixed-strings] [-n | --line-number]\r
23            [-l | --files-with-matches] [-L | --files-without-match]\r
24            [(-O | --open-files-in-pager) [&lt;pager&gt;]]\r
25            [-z | --null]\r
26            [-c | --count] [--all-match] [-q | --quiet]\r
27            [--max-depth &lt;depth&gt;]\r
28            [--color[=&lt;when&gt;] | --no-color]\r
29            [--break] [--heading] [-p | --show-function]\r
30            [-A &lt;post-context&gt;] [-B &lt;pre-context&gt;] [-C &lt;context&gt;]\r
31            [-W | --function-context]\r
32            [-f &lt;file&gt;] [-e] &lt;pattern&gt;\r
33            [--and|--or|--not|(|)|-e &lt;pattern&gt;&#8230;]\r
34            [ [--exclude-standard] [--cached | --no-index | --untracked] | &lt;tree&gt;&#8230;]\r
35            [--] [&lt;pathspec&gt;&#8230;]</literallayout>\r
36 </blockquote>\r
37 </simplesect>\r
38 <simplesect id="_description">\r
39 <title>DESCRIPTION</title>\r
40 <simpara>Look for specified patterns in the tracked files in the work tree, blobs\r
41 registered in the index file, or blobs in given tree objects.</simpara>\r
42 </simplesect>\r
43 <simplesect id="_configuration">\r
44 <title>CONFIGURATION</title>\r
45 <variablelist>\r
46 <varlistentry>\r
47 <term>\r
48 grep.lineNumber\r
49 </term>\r
50 <listitem>\r
51 <simpara>\r
52         If set to true, enable <emphasis>-n</emphasis> option by default.\r
53 </simpara>\r
54 </listitem>\r
55 </varlistentry>\r
56 <varlistentry>\r
57 <term>\r
58 grep.extendedRegexp\r
59 </term>\r
60 <listitem>\r
61 <simpara>\r
62         If set to true, enable <emphasis>--extended-regexp</emphasis> option by default.\r
63 </simpara>\r
64 </listitem>\r
65 </varlistentry>\r
66 </variablelist>\r
67 </simplesect>\r
68 <simplesect id="_options">\r
69 <title>OPTIONS</title>\r
70 <variablelist>\r
71 <varlistentry>\r
72 <term>\r
73 --cached\r
74 </term>\r
75 <listitem>\r
76 <simpara>\r
77         Instead of searching tracked files in the working tree, search\r
78         blobs registered in the index file.\r
79 </simpara>\r
80 </listitem>\r
81 </varlistentry>\r
82 <varlistentry>\r
83 <term>\r
84 --no-index\r
85 </term>\r
86 <listitem>\r
87 <simpara>\r
88         Search files in the current directory that is not managed by git.\r
89 </simpara>\r
90 </listitem>\r
91 </varlistentry>\r
92 <varlistentry>\r
93 <term>\r
94 --untracked\r
95 </term>\r
96 <listitem>\r
97 <simpara>\r
98         In addition to searching in the tracked files in the working\r
99         tree, search also in untracked files.\r
100 </simpara>\r
101 </listitem>\r
102 </varlistentry>\r
103 <varlistentry>\r
104 <term>\r
105 --no-exclude-standard\r
106 </term>\r
107 <listitem>\r
108 <simpara>\r
109         Also search in ignored files by not honoring the <emphasis>.gitignore</emphasis>\r
110         mechanism. Only useful with <emphasis>--untracked</emphasis>.\r
111 </simpara>\r
112 </listitem>\r
113 </varlistentry>\r
114 <varlistentry>\r
115 <term>\r
116 --exclude-standard\r
117 </term>\r
118 <listitem>\r
119 <simpara>\r
120         Do not pay attention to ignored files specified via the <emphasis>.gitignore</emphasis>\r
121         mechanism.  Only useful when searching files in the current directory\r
122         with <emphasis>--no-index</emphasis>.\r
123 </simpara>\r
124 </listitem>\r
125 </varlistentry>\r
126 <varlistentry>\r
127 <term>\r
128 -a\r
129 </term>\r
130 <term>\r
131 --text\r
132 </term>\r
133 <listitem>\r
134 <simpara>\r
135         Process binary files as if they were text.\r
136 </simpara>\r
137 </listitem>\r
138 </varlistentry>\r
139 <varlistentry>\r
140 <term>\r
141 -i\r
142 </term>\r
143 <term>\r
144 --ignore-case\r
145 </term>\r
146 <listitem>\r
147 <simpara>\r
148         Ignore case differences between the patterns and the\r
149         files.\r
150 </simpara>\r
151 </listitem>\r
152 </varlistentry>\r
153 <varlistentry>\r
154 <term>\r
155 -I\r
156 </term>\r
157 <listitem>\r
158 <simpara>\r
159         Don't match the pattern in binary files.\r
160 </simpara>\r
161 </listitem>\r
162 </varlistentry>\r
163 <varlistentry>\r
164 <term>\r
165 --max-depth &lt;depth&gt;\r
166 </term>\r
167 <listitem>\r
168 <simpara>\r
169         For each &lt;pathspec&gt; given on command line, descend at most &lt;depth&gt;\r
170         levels of directories. A negative value means no limit.\r
171         This option is ignored if &lt;pathspec&gt; contains active wildcards.\r
172         In other words if "a*" matches a directory named "a*",\r
173         "*" is matched literally so --max-depth is still effective.\r
174 </simpara>\r
175 </listitem>\r
176 </varlistentry>\r
177 <varlistentry>\r
178 <term>\r
179 -w\r
180 </term>\r
181 <term>\r
182 --word-regexp\r
183 </term>\r
184 <listitem>\r
185 <simpara>\r
186         Match the pattern only at word boundary (either begin at the\r
187         beginning of a line, or preceded by a non-word character; end at\r
188         the end of a line or followed by a non-word character).\r
189 </simpara>\r
190 </listitem>\r
191 </varlistentry>\r
192 <varlistentry>\r
193 <term>\r
194 -v\r
195 </term>\r
196 <term>\r
197 --invert-match\r
198 </term>\r
199 <listitem>\r
200 <simpara>\r
201         Select non-matching lines.\r
202 </simpara>\r
203 </listitem>\r
204 </varlistentry>\r
205 <varlistentry>\r
206 <term>\r
207 -h\r
208 </term>\r
209 <term>\r
210 -H\r
211 </term>\r
212 <listitem>\r
213 <simpara>\r
214         By default, the command shows the filename for each\r
215         match.  <emphasis>-h</emphasis> option is used to suppress this output.\r
216         <emphasis>-H</emphasis> is there for completeness and does not do anything\r
217         except it overrides <emphasis>-h</emphasis> given earlier on the command\r
218         line.\r
219 </simpara>\r
220 </listitem>\r
221 </varlistentry>\r
222 <varlistentry>\r
223 <term>\r
224 --full-name\r
225 </term>\r
226 <listitem>\r
227 <simpara>\r
228         When run from a subdirectory, the command usually\r
229         outputs paths relative to the current directory.  This\r
230         option forces paths to be output relative to the project\r
231         top directory.\r
232 </simpara>\r
233 </listitem>\r
234 </varlistentry>\r
235 <varlistentry>\r
236 <term>\r
237 -E\r
238 </term>\r
239 <term>\r
240 --extended-regexp\r
241 </term>\r
242 <term>\r
243 -G\r
244 </term>\r
245 <term>\r
246 --basic-regexp\r
247 </term>\r
248 <listitem>\r
249 <simpara>\r
250         Use POSIX extended/basic regexp for patterns.  Default\r
251         is to use basic regexp.\r
252 </simpara>\r
253 </listitem>\r
254 </varlistentry>\r
255 <varlistentry>\r
256 <term>\r
257 -P\r
258 </term>\r
259 <term>\r
260 --perl-regexp\r
261 </term>\r
262 <listitem>\r
263 <simpara>\r
264         Use Perl-compatible regexp for patterns. Requires libpcre to be\r
265         compiled in.\r
266 </simpara>\r
267 </listitem>\r
268 </varlistentry>\r
269 <varlistentry>\r
270 <term>\r
271 -F\r
272 </term>\r
273 <term>\r
274 --fixed-strings\r
275 </term>\r
276 <listitem>\r
277 <simpara>\r
278         Use fixed strings for patterns (don't interpret pattern\r
279         as a regex).\r
280 </simpara>\r
281 </listitem>\r
282 </varlistentry>\r
283 <varlistentry>\r
284 <term>\r
285 -n\r
286 </term>\r
287 <term>\r
288 --line-number\r
289 </term>\r
290 <listitem>\r
291 <simpara>\r
292         Prefix the line number to matching lines.\r
293 </simpara>\r
294 </listitem>\r
295 </varlistentry>\r
296 <varlistentry>\r
297 <term>\r
298 -l\r
299 </term>\r
300 <term>\r
301 --files-with-matches\r
302 </term>\r
303 <term>\r
304 --name-only\r
305 </term>\r
306 <term>\r
307 -L\r
308 </term>\r
309 <term>\r
310 --files-without-match\r
311 </term>\r
312 <listitem>\r
313 <simpara>\r
314         Instead of showing every matched line, show only the\r
315         names of files that contain (or do not contain) matches.\r
316         For better compatibility with <emphasis>git diff</emphasis>, <emphasis>--name-only</emphasis> is a\r
317         synonym for <emphasis>--files-with-matches</emphasis>.\r
318 </simpara>\r
319 </listitem>\r
320 </varlistentry>\r
321 <varlistentry>\r
322 <term>\r
323 -O [&lt;pager&gt;]\r
324 </term>\r
325 <term>\r
326 --open-files-in-pager [&lt;pager&gt;]\r
327 </term>\r
328 <listitem>\r
329 <simpara>\r
330         Open the matching files in the pager (not the output of <emphasis>grep</emphasis>).\r
331         If the pager happens to be "less" or "vi", and the user\r
332         specified only one pattern, the first file is positioned at\r
333         the first match automatically.\r
334 </simpara>\r
335 </listitem>\r
336 </varlistentry>\r
337 <varlistentry>\r
338 <term>\r
339 -z\r
340 </term>\r
341 <term>\r
342 --null\r
343 </term>\r
344 <listitem>\r
345 <simpara>\r
346         Output \0 instead of the character that normally follows a\r
347         file name.\r
348 </simpara>\r
349 </listitem>\r
350 </varlistentry>\r
351 <varlistentry>\r
352 <term>\r
353 -c\r
354 </term>\r
355 <term>\r
356 --count\r
357 </term>\r
358 <listitem>\r
359 <simpara>\r
360         Instead of showing every matched line, show the number of\r
361         lines that match.\r
362 </simpara>\r
363 </listitem>\r
364 </varlistentry>\r
365 <varlistentry>\r
366 <term>\r
367 --color[=&lt;when&gt;]\r
368 </term>\r
369 <listitem>\r
370 <simpara>\r
371         Show colored matches.\r
372         The value must be always (the default), never, or auto.\r
373 </simpara>\r
374 </listitem>\r
375 </varlistentry>\r
376 <varlistentry>\r
377 <term>\r
378 --no-color\r
379 </term>\r
380 <listitem>\r
381 <simpara>\r
382         Turn off match highlighting, even when the configuration file\r
383         gives the default to color output.\r
384         Same as <emphasis>--color=never</emphasis>.\r
385 </simpara>\r
386 </listitem>\r
387 </varlistentry>\r
388 <varlistentry>\r
389 <term>\r
390 --break\r
391 </term>\r
392 <listitem>\r
393 <simpara>\r
394         Print an empty line between matches from different files.\r
395 </simpara>\r
396 </listitem>\r
397 </varlistentry>\r
398 <varlistentry>\r
399 <term>\r
400 --heading\r
401 </term>\r
402 <listitem>\r
403 <simpara>\r
404         Show the filename above the matches in that file instead of\r
405         at the start of each shown line.\r
406 </simpara>\r
407 </listitem>\r
408 </varlistentry>\r
409 <varlistentry>\r
410 <term>\r
411 -p\r
412 </term>\r
413 <term>\r
414 --show-function\r
415 </term>\r
416 <listitem>\r
417 <simpara>\r
418         Show the preceding line that contains the function name of\r
419         the match, unless the matching line is a function name itself.\r
420         The name is determined in the same way as <emphasis>git diff</emphasis> works out\r
421         patch hunk headers (see <emphasis>Defining a custom hunk-header</emphasis> in\r
422         <xref linkend="gitattributes(5)" />).\r
423 </simpara>\r
424 </listitem>\r
425 </varlistentry>\r
426 <varlistentry>\r
427 <term>\r
428 -&lt;num&gt;\r
429 </term>\r
430 <term>\r
431 -C &lt;num&gt;\r
432 </term>\r
433 <term>\r
434 --context &lt;num&gt;\r
435 </term>\r
436 <listitem>\r
437 <simpara>\r
438         Show &lt;num&gt; leading and trailing lines, and place a line\r
439         containing <emphasis>--</emphasis> between contiguous groups of matches.\r
440 </simpara>\r
441 </listitem>\r
442 </varlistentry>\r
443 <varlistentry>\r
444 <term>\r
445 -A &lt;num&gt;\r
446 </term>\r
447 <term>\r
448 --after-context &lt;num&gt;\r
449 </term>\r
450 <listitem>\r
451 <simpara>\r
452         Show &lt;num&gt; trailing lines, and place a line containing\r
453         <emphasis>--</emphasis> between contiguous groups of matches.\r
454 </simpara>\r
455 </listitem>\r
456 </varlistentry>\r
457 <varlistentry>\r
458 <term>\r
459 -B &lt;num&gt;\r
460 </term>\r
461 <term>\r
462 --before-context &lt;num&gt;\r
463 </term>\r
464 <listitem>\r
465 <simpara>\r
466         Show &lt;num&gt; leading lines, and place a line containing\r
467         <emphasis>--</emphasis> between contiguous groups of matches.\r
468 </simpara>\r
469 </listitem>\r
470 </varlistentry>\r
471 <varlistentry>\r
472 <term>\r
473 -W\r
474 </term>\r
475 <term>\r
476 --function-context\r
477 </term>\r
478 <listitem>\r
479 <simpara>\r
480         Show the surrounding text from the previous line containing a\r
481         function name up to the one before the next function name,\r
482         effectively showing the whole function in which the match was\r
483         found.\r
484 </simpara>\r
485 </listitem>\r
486 </varlistentry>\r
487 <varlistentry>\r
488 <term>\r
489 -f &lt;file&gt;\r
490 </term>\r
491 <listitem>\r
492 <simpara>\r
493         Read patterns from &lt;file&gt;, one per line.\r
494 </simpara>\r
495 </listitem>\r
496 </varlistentry>\r
497 <varlistentry>\r
498 <term>\r
499 -e\r
500 </term>\r
501 <listitem>\r
502 <simpara>\r
503         The next parameter is the pattern. This option has to be\r
504         used for patterns starting with <emphasis>-</emphasis> and should be used in\r
505         scripts passing user input to grep.  Multiple patterns are\r
506         combined by <emphasis>or</emphasis>.\r
507 </simpara>\r
508 </listitem>\r
509 </varlistentry>\r
510 <varlistentry>\r
511 <term>\r
512 --and\r
513 </term>\r
514 <term>\r
515 --or\r
516 </term>\r
517 <term>\r
518 --not\r
519 </term>\r
520 <term>\r
521 ( &#8230; )\r
522 </term>\r
523 <listitem>\r
524 <simpara>\r
525         Specify how multiple patterns are combined using Boolean\r
526         expressions.  <emphasis>--or</emphasis> is the default operator.  <emphasis>--and</emphasis> has\r
527         higher precedence than <emphasis>--or</emphasis>.  <emphasis>-e</emphasis> has to be used for all\r
528         patterns.\r
529 </simpara>\r
530 </listitem>\r
531 </varlistentry>\r
532 <varlistentry>\r
533 <term>\r
534 --all-match\r
535 </term>\r
536 <listitem>\r
537 <simpara>\r
538         When giving multiple pattern expressions combined with <emphasis>--or</emphasis>,\r
539         this flag is specified to limit the match to files that\r
540         have lines to match all of them.\r
541 </simpara>\r
542 </listitem>\r
543 </varlistentry>\r
544 <varlistentry>\r
545 <term>\r
546 -q\r
547 </term>\r
548 <term>\r
549 --quiet\r
550 </term>\r
551 <listitem>\r
552 <simpara>\r
553         Do not output matched lines; instead, exit with status 0 when\r
554         there is a match and with non-zero status when there isn't.\r
555 </simpara>\r
556 </listitem>\r
557 </varlistentry>\r
558 <varlistentry>\r
559 <term>\r
560 &lt;tree&gt;&#8230;\r
561 </term>\r
562 <listitem>\r
563 <simpara>\r
564         Instead of searching tracked files in the working tree, search\r
565         blobs in the given trees.\r
566 </simpara>\r
567 </listitem>\r
568 </varlistentry>\r
569 <varlistentry>\r
570 <term>\r
571 --\r
572 </term>\r
573 <listitem>\r
574 <simpara>\r
575         Signals the end of options; the rest of the parameters\r
576         are &lt;pathspec&gt; limiters.\r
577 </simpara>\r
578 </listitem>\r
579 </varlistentry>\r
580 <varlistentry>\r
581 <term>\r
582 &lt;pathspec&gt;&#8230;\r
583 </term>\r
584 <listitem>\r
585 <simpara>\r
586         If given, limit the search to paths matching at least one pattern.\r
587         Both leading paths match and glob(7) patterns are supported.\r
588 </simpara>\r
589 </listitem>\r
590 </varlistentry>\r
591 </variablelist>\r
592 </simplesect>\r
593 <simplesect id="_examples">\r
594 <title>Examples</title>\r
595 <variablelist>\r
596 <varlistentry>\r
597 <term>\r
598 <emphasis>git grep 'time_t' -- '*.[ch]'</emphasis>\r
599 </term>\r
600 <listitem>\r
601 <simpara>\r
602         Looks for <emphasis>time_t</emphasis> in all tracked .c and .h files in the working\r
603         directory and its subdirectories.\r
604 </simpara>\r
605 </listitem>\r
606 </varlistentry>\r
607 <varlistentry>\r
608 <term>\r
609 <emphasis>git grep -e '#define' --and \( -e MAX_PATH -e PATH_MAX \)</emphasis>\r
610 </term>\r
611 <listitem>\r
612 <simpara>\r
613         Looks for a line that has <emphasis>#define</emphasis> and either <emphasis>MAX_PATH</emphasis> or\r
614         <emphasis>PATH_MAX</emphasis>.\r
615 </simpara>\r
616 </listitem>\r
617 </varlistentry>\r
618 <varlistentry>\r
619 <term>\r
620 <emphasis>git grep --all-match -e NODE -e Unexpected</emphasis>\r
621 </term>\r
622 <listitem>\r
623 <simpara>\r
624         Looks for a line that has <emphasis>NODE</emphasis> or <emphasis>Unexpected</emphasis> in\r
625         files that have lines that match both.\r
626 </simpara>\r
627 </listitem>\r
628 </varlistentry>\r
629 </variablelist>\r
630 </simplesect>\r
631 <simplesect id="_git">\r
632 <title>GIT</title>\r
633 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
634 </simplesect>\r
635 </article>\r