blob: fccb82deb48ec75d25f948e7caa69a44e09f5832 [file] [log] [blame]
Junio C Hamano2aba3192005-09-12 19:39:15 -07001git-grep(1)
2===========
Junio C Hamano2aba3192005-09-12 19:39:15 -07003
4NAME
5----
Fredrik Kuivinen50014222006-03-09 17:24:37 +01006git-grep - Print lines matching a pattern
Junio C Hamano2aba3192005-09-12 19:39:15 -07007
8
9SYNOPSIS
10--------
Junio C Hamano1c571192006-05-08 13:28:49 -070011[verse]
Jonathan Niederb1889c32008-06-30 01:09:04 -050012'git grep' [--cached]
Junio C Hamano1c571192006-05-08 13:28:49 -070013 [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
Junio C Hamano17fd9652006-09-15 18:37:01 -070014 [-v | --invert-match] [-h|-H] [--full-name]
Andrew Rudercf0d7202007-04-26 23:58:58 -050015 [-E | --extended-regexp] [-G | --basic-regexp]
16 [-F | --fixed-strings] [-n]
17 [-l | --files-with-matches] [-L | --files-without-match]
Raphael Zimmerer83caecc2008-10-01 18:11:15 +020018 [-z | --null]
Junio C Hamano0ab7bef2006-09-27 17:50:52 -070019 [-c | --count] [--all-match]
René Scharfe7e8f59d2009-03-07 13:32:32 +010020 [--color | --no-color]
Junio C Hamano1c571192006-05-08 13:28:49 -070021 [-A <post-context>] [-B <pre-context>] [-C <context>]
Andrew Rudercf0d7202007-04-26 23:58:58 -050022 [-f <file>] [-e] <pattern>
23 [--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
Junio C Hamano1c571192006-05-08 13:28:49 -070024 [--] [<path>...]
Junio C Hamano2aba3192005-09-12 19:39:15 -070025
26DESCRIPTION
27-----------
Junio C Hamano1c571192006-05-08 13:28:49 -070028Look for specified patterns in the working tree files, blobs
29registered in the index file, or given tree objects.
Junio C Hamano2aba3192005-09-12 19:39:15 -070030
31
32OPTIONS
33-------
Junio C Hamano1c571192006-05-08 13:28:49 -070034--cached::
35 Instead of searching in the working tree files, check
Horst H. von Brandabda1ef2006-06-03 16:27:26 -040036 the blobs registered in the index file.
Junio C Hamano1c571192006-05-08 13:28:49 -070037
Stephan Beyer32402402008-06-08 03:36:09 +020038-a::
39--text::
Junio C Hamano1c571192006-05-08 13:28:49 -070040 Process binary files as if they were text.
41
Stephan Beyer32402402008-06-08 03:36:09 +020042-i::
43--ignore-case::
Junio C Hamano1c571192006-05-08 13:28:49 -070044 Ignore case differences between the patterns and the
45 files.
46
Andrew Rudercf0d7202007-04-26 23:58:58 -050047-I::
48 Don't match the pattern in binary files.
49
Stephan Beyer32402402008-06-08 03:36:09 +020050-w::
51--word-regexp::
Junio C Hamano1c571192006-05-08 13:28:49 -070052 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
Stephan Beyer32402402008-06-08 03:36:09 +020056-v::
57--invert-match::
Junio C Hamano1c571192006-05-08 13:28:49 -070058 Select non-matching lines.
59
Stephan Beyer32402402008-06-08 03:36:09 +020060-h::
61-H::
Junio C Hamano17fd9652006-09-15 18:37:01 -070062 By default, the command shows the filename for each
63 match. `-h` option is used to suppress this output.
64 `-H` is there for completeness and does not do anything
65 except it overrides `-h` given earlier on the command
66 line.
67
Junio C Hamano0d042fe2006-08-11 00:44:42 -070068--full-name::
69 When run from a subdirectory, the command usually
70 outputs paths relative to the current directory. This
71 option forces paths to be output relative to the project
72 top directory.
73
Stephan Beyer32402402008-06-08 03:36:09 +020074-E::
75--extended-regexp::
76-G::
77--basic-regexp::
Junio C Hamano1c571192006-05-08 13:28:49 -070078 Use POSIX extended/basic regexp for patterns. Default
79 is to use basic regexp.
80
Stephan Beyer32402402008-06-08 03:36:09 +020081-F::
82--fixed-strings::
Andrew Rudercf0d7202007-04-26 23:58:58 -050083 Use fixed strings for patterns (don't interpret pattern
84 as a regex).
85
Junio C Hamano1c571192006-05-08 13:28:49 -070086-n::
87 Prefix the line number to matching lines.
88
Stephan Beyer32402402008-06-08 03:36:09 +020089-l::
90--files-with-matches::
91--name-only::
92-L::
93--files-without-match::
Junio C Hamano1c571192006-05-08 13:28:49 -070094 Instead of showing every matched line, show only the
95 names of files that contain (or do not contain) matches.
Jonathan Niederba020ef2008-07-03 00:41:41 -050096 For better compatibility with 'git-diff', --name-only is a
Shawn O. Pearce2cd5dfd2008-02-20 23:28:07 -050097 synonym for --files-with-matches.
Junio C Hamano1c571192006-05-08 13:28:49 -070098
Raphael Zimmerer83caecc2008-10-01 18:11:15 +020099-z::
100--null::
101 Output \0 instead of the character that normally follows a
102 file name.
103
Stephan Beyer32402402008-06-08 03:36:09 +0200104-c::
105--count::
Junio C Hamano1c571192006-05-08 13:28:49 -0700106 Instead of showing every matched line, show the number of
107 lines that match.
108
René Scharfe7e8f59d2009-03-07 13:32:32 +0100109--color::
110 Show colored matches.
111
112--no-color::
113 Turn off match highlighting, even when the configuration file
114 gives the default to color output.
115
Junio C Hamano1c571192006-05-08 13:28:49 -0700116-[ABC] <context>::
117 Show `context` trailing (`A` -- after), or leading (`B`
118 -- before), or both (`C` -- context) lines, and place a
Horst H. von Brandabda1ef2006-06-03 16:27:26 -0400119 line containing `--` between contiguous groups of
Junio C Hamano1c571192006-05-08 13:28:49 -0700120 matches.
121
Andrew Rudercf0d7202007-04-26 23:58:58 -0500122-<num>::
123 A shortcut for specifying -C<num>.
124
Junio C Hamano1c571192006-05-08 13:28:49 -0700125-f <file>::
126 Read patterns from <file>, one per line.
127
Matthias Lederhofer3acb27b2006-06-25 18:07:15 +0200128-e::
129 The next parameter is the pattern. This option has to be
130 used for patterns starting with - and should be used in
Matthias Lederhoferfba0cbd2006-08-03 00:04:56 +0200131 scripts passing user input to grep. Multiple patterns are
132 combined by 'or'.
133
Stephan Beyer32402402008-06-08 03:36:09 +0200134--and::
135--or::
136--not::
137( ... )::
René Scharfe23bfbb82007-01-17 16:32:41 +0100138 Specify how multiple patterns are combined using Boolean
Matthias Lederhoferfba0cbd2006-08-03 00:04:56 +0200139 expressions. `--or` is the default operator. `--and` has
140 higher precedence than `--or`. `-e` has to be used for all
141 patterns.
Matthias Lederhofer3acb27b2006-06-25 18:07:15 +0200142
Junio C Hamano0ab7bef2006-09-27 17:50:52 -0700143--all-match::
144 When giving multiple pattern expressions combined with `--or`,
145 this flag is specified to limit the match to files that
146 have lines to match all of them.
147
Junio C Hamano1c571192006-05-08 13:28:49 -0700148`<tree>...`::
149 Search blobs in the trees for specified patterns.
150
Matthias Lederhoferfba0cbd2006-08-03 00:04:56 +0200151\--::
Junio C Hamano5b2bcc72006-01-20 15:00:12 -0800152 Signals the end of options; the rest of the parameters
153 are <path> limiters.
154
Junio C Hamano2aba3192005-09-12 19:39:15 -0700155
Matthias Lederhoferfba0cbd2006-08-03 00:04:56 +0200156Example
157-------
158
159git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
160 Looks for a line that has `#define` and either `MAX_PATH` or
161 `PATH_MAX`.
162
Junio C Hamano0ab7bef2006-09-27 17:50:52 -0700163git grep --all-match -e NODE -e Unexpected::
164 Looks for a line that has `NODE` or `Unexpected` in
165 files that have lines that match both.
166
Junio C Hamano2aba3192005-09-12 19:39:15 -0700167Author
168------
Junio C Hamano1c571192006-05-08 13:28:49 -0700169Originally written by Linus Torvalds <torvalds@osdl.org>, later
170revamped by Junio C Hamano.
171
Junio C Hamano2aba3192005-09-12 19:39:15 -0700172
173Documentation
174--------------
175Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
176
177GIT
178---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200179Part of the linkgit:git[1] suite