]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-grep.txt
Merge branch 'kk/maint-prefix-in-config-mak'
[thirdparty/git.git] / Documentation / git-grep.txt
CommitLineData
2aba319a
JH
1git-grep(1)
2===========
2aba319a
JH
3
4NAME
5----
5001422d 6git-grep - Print lines matching a pattern
2aba319a
JH
7
8
9SYNOPSIS
10--------
1c57119c 11[verse]
ec2537be 12'git grep' [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
17fd965d 13 [-v | --invert-match] [-h|-H] [--full-name]
cf0d720b 14 [-E | --extended-regexp] [-G | --basic-regexp]
63e7e9d8 15 [-P | --perl-regexp]
d2355d76 16 [-F | --fixed-strings] [-n | --line-number]
cf0d720b 17 [-l | --files-with-matches] [-L | --files-without-match]
0af88c15 18 [(-O | --open-files-in-pager) [<pager>]]
83caecca 19 [-z | --null]
4ff61c21 20 [-c | --count] [--all-match] [-q | --quiet]
a91f453f 21 [--max-depth <depth>]
73e9da01 22 [--color[=<when>] | --no-color]
1c57119c 23 [-A <post-context>] [-B <pre-context>] [-C <context>]
cf0d720b 24 [-f <file>] [-e] <pattern>
ec2537be 25 [--and|--or|--not|(|)|-e <pattern>...]
2e48fcdb 26 [--cached | --no-index | <tree>...]
3ac44408 27 [--] [<pathspec>...]
2aba319a
JH
28
29DESCRIPTION
30-----------
3ac44408
ML
31Look for specified patterns in the tracked files in the work tree, blobs
32registered in the index file, or blobs in given tree objects.
2aba319a
JH
33
34
b22520a3
JR
35CONFIGURATION
36-------------
37
38grep.lineNumber::
39 If set to true, enable '-n' option by default.
40
41grep.extendedRegexp::
42 If set to true, enable '--extended-regexp' option by default.
43
44
2aba319a
JH
45OPTIONS
46-------
1c57119c 47--cached::
2e48fcdb
ML
48 Instead of searching tracked files in the working tree, search
49 blobs registered in the index file.
50
51--no-index::
52 Search files in the current directory, not just those tracked by git.
1c57119c 53
3240240f
SB
54-a::
55--text::
1c57119c
JH
56 Process binary files as if they were text.
57
3240240f
SB
58-i::
59--ignore-case::
1c57119c
JH
60 Ignore case differences between the patterns and the
61 files.
62
cf0d720b
AR
63-I::
64 Don't match the pattern in binary files.
65
a91f453f 66--max-depth <depth>::
3ac44408 67 For each <pathspec> given on command line, descend at most <depth>
a91f453f
MK
68 levels of directories. A negative value means no limit.
69
3240240f
SB
70-w::
71--word-regexp::
1c57119c
JH
72 Match the pattern only at word boundary (either begin at the
73 beginning of a line, or preceded by a non-word character; end at
74 the end of a line or followed by a non-word character).
75
3240240f
SB
76-v::
77--invert-match::
1c57119c
JH
78 Select non-matching lines.
79
3240240f
SB
80-h::
81-H::
17fd965d
JH
82 By default, the command shows the filename for each
83 match. `-h` option is used to suppress this output.
84 `-H` is there for completeness and does not do anything
85 except it overrides `-h` given earlier on the command
86 line.
87
0d042fec
JH
88--full-name::
89 When run from a subdirectory, the command usually
90 outputs paths relative to the current directory. This
91 option forces paths to be output relative to the project
92 top directory.
93
3240240f
SB
94-E::
95--extended-regexp::
96-G::
97--basic-regexp::
1c57119c
JH
98 Use POSIX extended/basic regexp for patterns. Default
99 is to use basic regexp.
5b2bcc7b 100
63e7e9d8
MK
101-P::
102--perl-regexp::
103 Use Perl-compatible regexp for patterns. Requires libpcre to be
104 compiled in.
105
3240240f
SB
106-F::
107--fixed-strings::
cf0d720b
AR
108 Use fixed strings for patterns (don't interpret pattern
109 as a regex).
110
1c57119c 111-n::
7d6cb10b 112--line-number::
1c57119c 113 Prefix the line number to matching lines.
2aba319a 114
3240240f
SB
115-l::
116--files-with-matches::
117--name-only::
118-L::
119--files-without-match::
1c57119c
JH
120 Instead of showing every matched line, show only the
121 names of files that contain (or do not contain) matches.
bfb8306d
ML
122 For better compatibility with 'git diff', `--name-only` is a
123 synonym for `--files-with-matches`.
2aba319a 124
0af88c15
JS
125-O [<pager>]::
126--open-files-in-pager [<pager>]::
678e484b
JS
127 Open the matching files in the pager (not the output of 'grep').
128 If the pager happens to be "less" or "vi", and the user
129 specified only one pattern, the first file is positioned at
130 the first match automatically.
131
83caecca
RZ
132-z::
133--null::
134 Output \0 instead of the character that normally follows a
135 file name.
136
3240240f
SB
137-c::
138--count::
1c57119c
JH
139 Instead of showing every matched line, show the number of
140 lines that match.
141
73e9da01 142--color[=<when>]::
7e8f59d5 143 Show colored matches.
73e9da01 144 The value must be always (the default), never, or auto.
7e8f59d5
RS
145
146--no-color::
147 Turn off match highlighting, even when the configuration file
148 gives the default to color output.
73e9da01 149 Same as `--color=never`.
7e8f59d5 150
1c57119c
JH
151-[ABC] <context>::
152 Show `context` trailing (`A` -- after), or leading (`B`
153 -- before), or both (`C` -- context) lines, and place a
abda1ef5 154 line containing `--` between contiguous groups of
1c57119c
JH
155 matches.
156
cf0d720b 157-<num>::
bfb8306d 158 A shortcut for specifying `-C<num>`.
cf0d720b 159
2944e4e6
RS
160-p::
161--show-function::
162 Show the preceding line that contains the function name of
163 the match, unless the matching line is a function name itself.
60ecac98
RS
164 The name is determined in the same way as 'git diff' works out
165 patch hunk headers (see 'Defining a custom hunk-header' in
166 linkgit:gitattributes[5]).
2944e4e6 167
1c57119c
JH
168-f <file>::
169 Read patterns from <file>, one per line.
170
3acb27b6
ML
171-e::
172 The next parameter is the pattern. This option has to be
bfb8306d 173 used for patterns starting with `-` and should be used in
fba0cbd9
ML
174 scripts passing user input to grep. Multiple patterns are
175 combined by 'or'.
176
3240240f
SB
177--and::
178--or::
179--not::
180( ... )::
23bfbb81 181 Specify how multiple patterns are combined using Boolean
fba0cbd9
ML
182 expressions. `--or` is the default operator. `--and` has
183 higher precedence than `--or`. `-e` has to be used for all
184 patterns.
3acb27b6 185
0ab7befa
JH
186--all-match::
187 When giving multiple pattern expressions combined with `--or`,
188 this flag is specified to limit the match to files that
189 have lines to match all of them.
190
4ff61c21
JH
191-q::
192--quiet::
193 Do not output matched lines; instead, exit with status 0 when
194 there is a match and with non-zero status when there isn't.
195
bfb8306d 196<tree>...::
2e48fcdb
ML
197 Instead of searching tracked files in the working tree, search
198 blobs in the given trees.
1c57119c 199
fba0cbd9 200\--::
1c57119c 201 Signals the end of options; the rest of the parameters
3ac44408 202 are <pathspec> limiters.
2aba319a 203
3ac44408
ML
204<pathspec>...::
205 If given, limit the search to paths matching at least one pattern.
206 Both leading paths match and glob(7) patterns are supported.
2aba319a 207
04416018
ML
208Examples
209--------
fba0cbd9 210
3988da06 211git grep {apostrophe}time_t{apostrophe} \-- {apostrophe}*.[ch]{apostrophe}::
3ac44408
ML
212 Looks for `time_t` in all tracked .c and .h files in the working
213 directory and its subdirectories.
214
3988da06 215git grep -e {apostrophe}#define{apostrophe} --and \( -e MAX_PATH -e PATH_MAX \)::
fba0cbd9
ML
216 Looks for a line that has `#define` and either `MAX_PATH` or
217 `PATH_MAX`.
218
0ab7befa
JH
219git grep --all-match -e NODE -e Unexpected::
220 Looks for a line that has `NODE` or `Unexpected` in
221 files that have lines that match both.
222
2aba319a
JH
223GIT
224---
9e1f0a85 225Part of the linkgit:git[1] suite