grep: teach --untracked and --exclude-standard options
[git/jnareb-git.git] / Documentation / git-grep.txt
blob6269007b9449aea8a762849b28a80561174e4438
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] [--untracked] [--exclude-standard]
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 | --no-color]
22            [-A <post-context>] [-B <pre-context>] [-C <context>]
23            [-f <file>] [-e] <pattern>
24            [--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
25            [--] [<path>...]
27 DESCRIPTION
28 -----------
29 Look for specified patterns in the working tree files, blobs
30 registered in the index file, or 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 --untracked::
40         In addition to searching in the tracked files in the working
41         tree, search also in untracked files.
43 --no-exclude-standard::
44         Also search in ignored files by not honoring the `.gitignore`
45         mechanism. Only useful with `--untracked`.
47 --exclude-standard::
48         Do not pay attention to ignored files specified via the `.gitignore`
49         mechanism.  Only useful when searching files in the current directory
50         with `--no-index`.
52 -a::
53 --text::
54         Process binary files as if they were text.
56 -i::
57 --ignore-case::
58         Ignore case differences between the patterns and the
59         files.
61 -I::
62         Don't match the pattern in binary files.
64 --max-depth <depth>::
65         For each pathspec given on command line, descend at most <depth>
66         levels of directories. A negative value means no limit.
68 -w::
69 --word-regexp::
70         Match the pattern only at word boundary (either begin at the
71         beginning of a line, or preceded by a non-word character; end at
72         the end of a line or followed by a non-word character).
74 -v::
75 --invert-match::
76         Select non-matching lines.
78 -h::
79 -H::
80         By default, the command shows the filename for each
81         match.  `-h` option is used to suppress this output.
82         `-H` is there for completeness and does not do anything
83         except it overrides `-h` given earlier on the command
84         line.
86 --full-name::
87         When run from a subdirectory, the command usually
88         outputs paths relative to the current directory.  This
89         option forces paths to be output relative to the project
90         top directory.
92 -E::
93 --extended-regexp::
94 -G::
95 --basic-regexp::
96         Use POSIX extended/basic regexp for patterns.  Default
97         is to use basic regexp.
99 -F::
100 --fixed-strings::
101         Use fixed strings for patterns (don't interpret pattern
102         as a regex).
104 -n::
105         Prefix the line number to matching lines.
107 -l::
108 --files-with-matches::
109 --name-only::
110 -L::
111 --files-without-match::
112         Instead of showing every matched line, show only the
113         names of files that contain (or do not contain) matches.
114         For better compatibility with 'git diff', --name-only is a
115         synonym for --files-with-matches.
117 -z::
118 --null::
119         Output \0 instead of the character that normally follows a
120         file name.
122 -c::
123 --count::
124         Instead of showing every matched line, show the number of
125         lines that match.
127 --color::
128         Show colored matches.
130 --no-color::
131         Turn off match highlighting, even when the configuration file
132         gives the default to color output.
134 -[ABC] <context>::
135         Show `context` trailing (`A` -- after), or leading (`B`
136         -- before), or both (`C` -- context) lines, and place a
137         line containing `--` between contiguous groups of
138         matches.
140 -<num>::
141         A shortcut for specifying -C<num>.
143 -p::
144 --show-function::
145         Show the preceding line that contains the function name of
146         the match, unless the matching line is a function name itself.
147         The name is determined in the same way as 'git diff' works out
148         patch hunk headers (see 'Defining a custom hunk-header' in
149         linkgit:gitattributes[5]).
151 -f <file>::
152         Read patterns from <file>, one per line.
154 -e::
155         The next parameter is the pattern. This option has to be
156         used for patterns starting with - and should be used in
157         scripts passing user input to grep.  Multiple patterns are
158         combined by 'or'.
160 --and::
161 --or::
162 --not::
163 ( ... )::
164         Specify how multiple patterns are combined using Boolean
165         expressions.  `--or` is the default operator.  `--and` has
166         higher precedence than `--or`.  `-e` has to be used for all
167         patterns.
169 --all-match::
170         When giving multiple pattern expressions combined with `--or`,
171         this flag is specified to limit the match to files that
172         have lines to match all of them.
174 -q::
175 --quiet::
176         Do not output matched lines; instead, exit with status 0 when
177         there is a match and with non-zero status when there isn't.
179 `<tree>...`::
180         Search blobs in the trees for specified patterns.
182 \--::
183         Signals the end of options; the rest of the parameters
184         are <path> limiters.
187 Example
188 -------
190 git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
191         Looks for a line that has `#define` and either `MAX_PATH` or
192         `PATH_MAX`.
194 git grep --all-match -e NODE -e Unexpected::
195         Looks for a line that has `NODE` or `Unexpected` in
196         files that have lines that match both.
198 Author
199 ------
200 Originally written by Linus Torvalds <torvalds@osdl.org>, later
201 revamped by Junio C Hamano.
204 Documentation
205 --------------
206 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
210 Part of the linkgit:git[1] suite