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