1GIT-GREP(1)                       Git Manual                       GIT-GREP(1)
2
3
4

NAME

6       git-grep - Print lines matching a pattern
7

SYNOPSIS

9       git grep [-a | --text] [-I] [--textconv] [-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                  [--threads <num>]
24                  [-f <file>] [-e] <pattern>
25                  [--and|--or|--not|(|)|-e <pattern>...]
26                  [--recurse-submodules] [--parent-basename <basename>]
27                  [ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | <tree>...]
28                  [--] [<pathspec>...]
29
30

DESCRIPTION

32       Look for specified patterns in the tracked files in the work tree,
33       blobs registered in the index file, or blobs in given tree objects.
34       Patterns are lists of one or more search expressions separated by
35       newline characters. An empty string as search expression matches all
36       lines.
37

CONFIGURATION

39       grep.lineNumber
40           If set to true, enable -n option by default.
41
42       grep.patternType
43           Set the default matching behavior. Using a value of basic,
44           extended, fixed, or perl will enable the --basic-regexp,
45           --extended-regexp, --fixed-strings, or --perl-regexp option
46           accordingly, while the value default will return to the default
47           matching behavior.
48
49       grep.extendedRegexp
50           If set to true, enable --extended-regexp option by default. This
51           option is ignored when the grep.patternType option is set to a
52           value other than default.
53
54       grep.threads
55           Number of grep worker threads to use. If unset (or set to 0), 8
56           threads are used by default (for now).
57
58       grep.fullName
59           If set to true, enable --full-name option by default.
60
61       grep.fallbackToNoIndex
62           If set to true, fall back to git grep --no-index if git grep is
63           executed outside of a git repository. Defaults to false.
64

OPTIONS

66       --cached
67           Instead of searching tracked files in the working tree, search
68           blobs registered in the index file.
69
70       --no-index
71           Search files in the current directory that is not managed by Git.
72
73       --untracked
74           In addition to searching in the tracked files in the working tree,
75           search also in untracked files.
76
77       --no-exclude-standard
78           Also search in ignored files by not honoring the .gitignore
79           mechanism. Only useful with --untracked.
80
81       --exclude-standard
82           Do not pay attention to ignored files specified via the .gitignore
83           mechanism. Only useful when searching files in the current
84           directory with --no-index.
85
86       --recurse-submodules
87           Recursively search in each submodule that has been initialized and
88           checked out in the repository. When used in combination with the
89           <tree> option the prefix of all submodule output will be the name
90           of the parent project’s <tree> object.
91
92       -a, --text
93           Process binary files as if they were text.
94
95       --textconv
96           Honor textconv filter settings.
97
98       --no-textconv
99           Do not honor textconv filter settings. This is the default.
100
101       -i, --ignore-case
102           Ignore case differences between the patterns and the files.
103
104       -I
105           Don’t match the pattern in binary files.
106
107       --max-depth <depth>
108           For each <pathspec> given on command line, descend at most <depth>
109           levels of directories. A negative value means no limit. This option
110           is ignored if <pathspec> contains active wildcards. In other words
111           if "a*" matches a directory named "a*", "*" is matched literally so
112           --max-depth is still effective.
113
114       -w, --word-regexp
115           Match the pattern only at word boundary (either begin at the
116           beginning of a line, or preceded by a non-word character; end at
117           the end of a line or followed by a non-word character).
118
119       -v, --invert-match
120           Select non-matching lines.
121
122       -h, -H
123           By default, the command shows the filename for each match.  -h
124           option is used to suppress this output.  -H is there for
125           completeness and does not do anything except it overrides -h given
126           earlier on the command line.
127
128       --full-name
129           When run from a subdirectory, the command usually outputs paths
130           relative to the current directory. This option forces paths to be
131           output relative to the project top directory.
132
133       -E, --extended-regexp, -G, --basic-regexp
134           Use POSIX extended/basic regexp for patterns. Default is to use
135           basic regexp.
136
137       -P, --perl-regexp
138           Use Perl-compatible regular expressions for patterns.
139
140           Support for these types of regular expressions is an optional
141           compile-time dependency. If Git wasn’t compiled with support for
142           them providing this option will cause it to die.
143
144       -F, --fixed-strings
145           Use fixed strings for patterns (don’t interpret pattern as a
146           regex).
147
148       -n, --line-number
149           Prefix the line number to matching lines.
150
151       -l, --files-with-matches, --name-only, -L, --files-without-match
152           Instead of showing every matched line, show only the names of files
153           that contain (or do not contain) matches. For better compatibility
154           with git diff, --name-only is a synonym for --files-with-matches.
155
156       -O[<pager>], --open-files-in-pager[=<pager>]
157           Open the matching files in the pager (not the output of grep). If
158           the pager happens to be "less" or "vi", and the user specified only
159           one pattern, the first file is positioned at the first match
160           automatically. The pager argument is optional; if specified, it
161           must be stuck to the option without a space. If pager is
162           unspecified, the default pager will be used (see core.pager in git-
163           config(1)).
164
165       -z, --null
166           Output \0 instead of the character that normally follows a file
167           name.
168
169       -c, --count
170           Instead of showing every matched line, show the number of lines
171           that match.
172
173       --color[=<when>]
174           Show colored matches. The value must be always (the default),
175           never, or auto.
176
177       --no-color
178           Turn off match highlighting, even when the configuration file gives
179           the default to color output. Same as --color=never.
180
181       --break
182           Print an empty line between matches from different files.
183
184       --heading
185           Show the filename above the matches in that file instead of at the
186           start of each shown line.
187
188       -p, --show-function
189           Show the preceding line that contains the function name of the
190           match, unless the matching line is a function name itself. The name
191           is determined in the same way as git diff works out patch hunk
192           headers (see Defining a custom hunk-header in gitattributes(5)).
193
194       -<num>, -C <num>, --context <num>
195           Show <num> leading and trailing lines, and place a line containing
196           -- between contiguous groups of matches.
197
198       -A <num>, --after-context <num>
199           Show <num> trailing lines, and place a line containing -- between
200           contiguous groups of matches.
201
202       -B <num>, --before-context <num>
203           Show <num> leading lines, and place a line containing -- between
204           contiguous groups of matches.
205
206       -W, --function-context
207           Show the surrounding text from the previous line containing a
208           function name up to the one before the next function name,
209           effectively showing the whole function in which the match was
210           found.
211
212       --threads <num>
213           Number of grep worker threads to use. See grep.threads in
214           CONFIGURATION for more information.
215
216       -f <file>
217           Read patterns from <file>, one per line.
218
219       -e
220           The next parameter is the pattern. This option has to be used for
221           patterns starting with - and should be used in scripts passing user
222           input to grep. Multiple patterns are combined by or.
223
224       --and, --or, --not, ( ... )
225           Specify how multiple patterns are combined using Boolean
226           expressions.  --or is the default operator.  --and has higher
227           precedence than --or.  -e has to be used for all patterns.
228
229       --all-match
230           When giving multiple pattern expressions combined with --or, this
231           flag is specified to limit the match to files that have lines to
232           match all of them.
233
234       -q, --quiet
235           Do not output matched lines; instead, exit with status 0 when there
236           is a match and with non-zero status when there isn’t.
237
238       <tree>...
239           Instead of searching tracked files in the working tree, search
240           blobs in the given trees.
241
242       --
243           Signals the end of options; the rest of the parameters are
244           <pathspec> limiters.
245
246       <pathspec>...
247           If given, limit the search to paths matching at least one pattern.
248           Both leading paths match and glob(7) patterns are supported.
249
250           For more details about the <pathspec> syntax, see the pathspec
251           entry in gitglossary(7).
252

EXAMPLES

254       git grep 'time_t' -- '*.[ch]'
255           Looks for time_t in all tracked .c and .h files in the working
256           directory and its subdirectories.
257
258       git grep -e '#define' --and \( -e MAX_PATH -e PATH_MAX \)
259           Looks for a line that has #define and either MAX_PATH or PATH_MAX.
260
261       git grep --all-match -e NODE -e Unexpected
262           Looks for a line that has NODE or Unexpected in files that have
263           lines that match both.
264
265       git grep solution -- :^Documentation
266           Looks for solution, excluding files in Documentation.
267

GIT

269       Part of the git(1) suite
270
271
272
273Git 2.18.1                        05/14/2019                       GIT-GREP(1)
Impressum