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