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