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