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