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