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