]>
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 JH |
11 | [verse] |
12 | 'git-grep' [--cached] | |
13 | [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp] | |
0d042fec | 14 | [-v | --invert-match] [--full-name] |
07ea91d8 | 15 | [-E | --extended-regexp] [-G | --basic-regexp] [-F | --fixed-strings] |
1c57119c JH |
16 | [-n] [-l | --files-with-matches] [-L | --files-without-match] |
17 | [-c | --count] | |
18 | [-A <post-context>] [-B <pre-context>] [-C <context>] | |
fba0cbd9 | 19 | [-f <file>] [-e] <pattern> [--and|--or|--not|(|)|-e <pattern>...] |
1c57119c JH |
20 | [<tree>...] |
21 | [--] [<path>...] | |
2aba319a JH |
22 | |
23 | DESCRIPTION | |
24 | ----------- | |
1c57119c JH |
25 | Look for specified patterns in the working tree files, blobs |
26 | registered in the index file, or given tree objects. | |
2aba319a JH |
27 | |
28 | ||
29 | OPTIONS | |
30 | ------- | |
1c57119c JH |
31 | --cached:: |
32 | Instead of searching in the working tree files, check | |
abda1ef5 | 33 | the blobs registered in the index file. |
1c57119c JH |
34 | |
35 | -a | --text:: | |
36 | Process binary files as if they were text. | |
37 | ||
38 | -i | --ignore-case:: | |
39 | Ignore case differences between the patterns and the | |
40 | files. | |
41 | ||
42 | -w | --word-regexp:: | |
43 | Match the pattern only at word boundary (either begin at the | |
44 | beginning of a line, or preceded by a non-word character; end at | |
45 | the end of a line or followed by a non-word character). | |
46 | ||
47 | -v | --invert-match:: | |
48 | Select non-matching lines. | |
49 | ||
0d042fec JH |
50 | --full-name:: |
51 | When run from a subdirectory, the command usually | |
52 | outputs paths relative to the current directory. This | |
53 | option forces paths to be output relative to the project | |
54 | top directory. | |
55 | ||
1c57119c JH |
56 | -E | --extended-regexp | -G | --basic-regexp:: |
57 | Use POSIX extended/basic regexp for patterns. Default | |
58 | is to use basic regexp. | |
5b2bcc7b | 59 | |
1c57119c JH |
60 | -n:: |
61 | Prefix the line number to matching lines. | |
2aba319a | 62 | |
1c57119c JH |
63 | -l | --files-with-matches | -L | --files-without-match:: |
64 | Instead of showing every matched line, show only the | |
65 | names of files that contain (or do not contain) matches. | |
2aba319a | 66 | |
1c57119c JH |
67 | -c | --count:: |
68 | Instead of showing every matched line, show the number of | |
69 | lines that match. | |
70 | ||
71 | -[ABC] <context>:: | |
72 | Show `context` trailing (`A` -- after), or leading (`B` | |
73 | -- before), or both (`C` -- context) lines, and place a | |
abda1ef5 | 74 | line containing `--` between contiguous groups of |
1c57119c JH |
75 | matches. |
76 | ||
77 | -f <file>:: | |
78 | Read patterns from <file>, one per line. | |
79 | ||
3acb27b6 ML |
80 | -e:: |
81 | The next parameter is the pattern. This option has to be | |
82 | used for patterns starting with - and should be used in | |
fba0cbd9 ML |
83 | scripts passing user input to grep. Multiple patterns are |
84 | combined by 'or'. | |
85 | ||
86 | --and | --or | --not | ( | ):: | |
87 | Specify how multiple patterns are combined using boolean | |
88 | expressions. `--or` is the default operator. `--and` has | |
89 | higher precedence than `--or`. `-e` has to be used for all | |
90 | patterns. | |
3acb27b6 | 91 | |
1c57119c JH |
92 | `<tree>...`:: |
93 | Search blobs in the trees for specified patterns. | |
94 | ||
fba0cbd9 | 95 | \--:: |
1c57119c JH |
96 | Signals the end of options; the rest of the parameters |
97 | are <path> limiters. | |
2aba319a JH |
98 | |
99 | ||
fba0cbd9 ML |
100 | Example |
101 | ------- | |
102 | ||
103 | git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \):: | |
104 | Looks for a line that has `#define` and either `MAX_PATH` or | |
105 | `PATH_MAX`. | |
106 | ||
2aba319a JH |
107 | Author |
108 | ------ | |
1c57119c JH |
109 | Originally written by Linus Torvalds <torvalds@osdl.org>, later |
110 | revamped by Junio C Hamano. | |
111 | ||
2aba319a JH |
112 | |
113 | Documentation | |
114 | -------------- | |
115 | Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. | |
116 | ||
117 | GIT | |
118 | --- | |
a7154e91 | 119 | Part of the gitlink:git[7] suite |
2aba319a | 120 |