1GIT-GREP(1) Git Manual GIT-GREP(1)
2
3
4
6 git-grep - Print lines matching a pattern
7
9 git grep [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
10 [-v | --invert-match] [-h|-H] [--full-name]
11 [-E | --extended-regexp] [-G | --basic-regexp]
12 [-P | --perl-regexp]
13 [-F | --fixed-strings] [-n | --line-number]
14 [-l | --files-with-matches] [-L | --files-without-match]
15 [(-O | --open-files-in-pager) [<pager>]]
16 [-z | --null]
17 [-c | --count] [--all-match] [-q | --quiet]
18 [--max-depth <depth>]
19 [--color[=<when>] | --no-color]
20 [--break] [--heading] [-p | --show-function]
21 [-A <post-context>] [-B <pre-context>] [-C <context>]
22 [-W | --function-context]
23 [-f <file>] [-e] <pattern>
24 [--and|--or|--not|(|)|-e <pattern>...]
25 [ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | <tree>...]
26 [--] [<pathspec>...]
27
28
30 Look for specified patterns in the tracked files in the work tree,
31 blobs registered in the index file, or blobs in given tree objects.
32 Patterns are lists of one or more search expressions separated by
33 newline characters. An empty string as search expression matches all
34 lines.
35
37 grep.lineNumber
38 If set to true, enable -n option by default.
39
40 grep.patternType
41 Set the default matching behavior. Using a value of basic,
42 extended, fixed, or perl will enable the --basic-regexp,
43 --extended-regexp, --fixed-strings, or --perl-regexp option
44 accordingly, while the value default will return to the default
45 matching behavior.
46
47 grep.extendedRegexp
48 If set to true, enable --extended-regexp option by default. This
49 option is ignored when the grep.patternType option is set to a
50 value other than default.
51
53 --cached
54 Instead of searching tracked files in the working tree, search
55 blobs registered in the index file.
56
57 --no-index
58 Search files in the current directory that is not managed by Git.
59
60 --untracked
61 In addition to searching in the tracked files in the working tree,
62 search also in untracked files.
63
64 --no-exclude-standard
65 Also search in ignored files by not honoring the .gitignore
66 mechanism. Only useful with --untracked.
67
68 --exclude-standard
69 Do not pay attention to ignored files specified via the .gitignore
70 mechanism. Only useful when searching files in the current
71 directory with --no-index.
72
73 -a, --text
74 Process binary files as if they were text.
75
76 -i, --ignore-case
77 Ignore case differences between the patterns and the files.
78
79 -I
80 Don’t match the pattern in binary files.
81
82 --max-depth <depth>
83 For each <pathspec> given on command line, descend at most <depth>
84 levels of directories. A negative value means no limit. This option
85 is ignored if <pathspec> contains active wildcards. In other words
86 if "a*" matches a directory named "a*", "*" is matched literally so
87 --max-depth is still effective.
88
89 -w, --word-regexp
90 Match the pattern only at word boundary (either begin at the
91 beginning of a line, or preceded by a non-word character; end at
92 the end of a line or followed by a non-word character).
93
94 -v, --invert-match
95 Select non-matching lines.
96
97 -h, -H
98 By default, the command shows the filename for each match. -h
99 option is used to suppress this output. -H is there for
100 completeness and does not do anything except it overrides -h given
101 earlier on the command line.
102
103 --full-name
104 When run from a subdirectory, the command usually outputs paths
105 relative to the current directory. This option forces paths to be
106 output relative to the project top directory.
107
108 -E, --extended-regexp, -G, --basic-regexp
109 Use POSIX extended/basic regexp for patterns. Default is to use
110 basic regexp.
111
112 -P, --perl-regexp
113 Use Perl-compatible regexp for patterns. Requires libpcre to be
114 compiled in.
115
116 -F, --fixed-strings
117 Use fixed strings for patterns (don’t interpret pattern as a
118 regex).
119
120 -n, --line-number
121 Prefix the line number to matching lines.
122
123 -l, --files-with-matches, --name-only, -L, --files-without-match
124 Instead of showing every matched line, show only the names of files
125 that contain (or do not contain) matches. For better compatibility
126 with git diff, --name-only is a synonym for --files-with-matches.
127
128 -O [<pager>], --open-files-in-pager [<pager>]
129 Open the matching files in the pager (not the output of grep). If
130 the pager happens to be "less" or "vi", and the user specified only
131 one pattern, the first file is positioned at the first match
132 automatically.
133
134 -z, --null
135 Output \0 instead of the character that normally follows a file
136 name.
137
138 -c, --count
139 Instead of showing every matched line, show the number of lines
140 that match.
141
142 --color[=<when>]
143 Show colored matches. The value must be always (the default),
144 never, or auto.
145
146 --no-color
147 Turn off match highlighting, even when the configuration file gives
148 the default to color output. Same as --color=never.
149
150 --break
151 Print an empty line between matches from different files.
152
153 --heading
154 Show the filename above the matches in that file instead of at the
155 start of each shown line.
156
157 -p, --show-function
158 Show the preceding line that contains the function name of the
159 match, unless the matching line is a function name itself. The name
160 is determined in the same way as git diff works out patch hunk
161 headers (see Defining a custom hunk-header in gitattributes(5)).
162
163 -<num>, -C <num>, --context <num>
164 Show <num> leading and trailing lines, and place a line containing
165 -- between contiguous groups of matches.
166
167 -A <num>, --after-context <num>
168 Show <num> trailing lines, and place a line containing -- between
169 contiguous groups of matches.
170
171 -B <num>, --before-context <num>
172 Show <num> leading lines, and place a line containing -- between
173 contiguous groups of matches.
174
175 -W, --function-context
176 Show the surrounding text from the previous line containing a
177 function name up to the one before the next function name,
178 effectively showing the whole function in which the match was
179 found.
180
181 -f <file>
182 Read patterns from <file>, one per line.
183
184 -e
185 The next parameter is the pattern. This option has to be used for
186 patterns starting with - and should be used in scripts passing user
187 input to grep. Multiple patterns are combined by or.
188
189 --and, --or, --not, ( ... )
190 Specify how multiple patterns are combined using Boolean
191 expressions. --or is the default operator. --and has higher
192 precedence than --or. -e has to be used for all patterns.
193
194 --all-match
195 When giving multiple pattern expressions combined with --or, this
196 flag is specified to limit the match to files that have lines to
197 match all of them.
198
199 -q, --quiet
200 Do not output matched lines; instead, exit with status 0 when there
201 is a match and with non-zero status when there isn’t.
202
203 <tree>...
204 Instead of searching tracked files in the working tree, search
205 blobs in the given trees.
206
207 --
208 Signals the end of options; the rest of the parameters are
209 <pathspec> limiters.
210
211 <pathspec>...
212 If given, limit the search to paths matching at least one pattern.
213 Both leading paths match and glob(7) patterns are supported.
214
216 git grep 'time_t' -- '*.[ch]'
217 Looks for time_t in all tracked .c and .h files in the working
218 directory and its subdirectories.
219
220 git grep -e '#define' --and \( -e MAX_PATH -e PATH_MAX \)
221 Looks for a line that has #define and either MAX_PATH or PATH_MAX.
222
223 git grep --all-match -e NODE -e Unexpected
224 Looks for a line that has NODE or Unexpected in files that have
225 lines that match both.
226
228 Part of the git(1) suite
229
230
231
232Git 1.8.3.1 11/19/2018 GIT-GREP(1)