2005-09-13 06:39:15 +04:00
|
|
|
git-grep(1)
|
|
|
|
===========
|
|
|
|
|
|
|
|
NAME
|
|
|
|
----
|
2006-03-09 19:24:37 +03:00
|
|
|
git-grep - Print lines matching a pattern
|
2005-09-13 06:39:15 +04:00
|
|
|
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
--------
|
2006-05-09 00:28:49 +04:00
|
|
|
[verse]
|
2008-06-30 10:09:04 +04:00
|
|
|
'git grep' [--cached]
|
2006-05-09 00:28:49 +04:00
|
|
|
[-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
|
2006-09-16 05:37:01 +04:00
|
|
|
[-v | --invert-match] [-h|-H] [--full-name]
|
2007-04-27 08:58:58 +04:00
|
|
|
[-E | --extended-regexp] [-G | --basic-regexp]
|
|
|
|
[-F | --fixed-strings] [-n]
|
|
|
|
[-l | --files-with-matches] [-L | --files-without-match]
|
2008-10-01 20:11:15 +04:00
|
|
|
[-z | --null]
|
2006-09-28 04:50:52 +04:00
|
|
|
[-c | --count] [--all-match]
|
2006-05-09 00:28:49 +04:00
|
|
|
[-A <post-context>] [-B <pre-context>] [-C <context>]
|
2007-04-27 08:58:58 +04:00
|
|
|
[-f <file>] [-e] <pattern>
|
|
|
|
[--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
|
2006-05-09 00:28:49 +04:00
|
|
|
[--] [<path>...]
|
2005-09-13 06:39:15 +04:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
2006-05-09 00:28:49 +04:00
|
|
|
Look for specified patterns in the working tree files, blobs
|
|
|
|
registered in the index file, or given tree objects.
|
2005-09-13 06:39:15 +04:00
|
|
|
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
-------
|
2006-05-09 00:28:49 +04:00
|
|
|
--cached::
|
|
|
|
Instead of searching in the working tree files, check
|
2006-06-04 00:27:26 +04:00
|
|
|
the blobs registered in the index file.
|
2006-05-09 00:28:49 +04:00
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
-a::
|
|
|
|
--text::
|
2006-05-09 00:28:49 +04:00
|
|
|
Process binary files as if they were text.
|
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
-i::
|
|
|
|
--ignore-case::
|
2006-05-09 00:28:49 +04:00
|
|
|
Ignore case differences between the patterns and the
|
|
|
|
files.
|
|
|
|
|
2007-04-27 08:58:58 +04:00
|
|
|
-I::
|
|
|
|
Don't match the pattern in binary files.
|
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
-w::
|
|
|
|
--word-regexp::
|
2006-05-09 00:28:49 +04:00
|
|
|
Match the pattern only at word boundary (either begin at the
|
|
|
|
beginning of a line, or preceded by a non-word character; end at
|
|
|
|
the end of a line or followed by a non-word character).
|
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
-v::
|
|
|
|
--invert-match::
|
2006-05-09 00:28:49 +04:00
|
|
|
Select non-matching lines.
|
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
-h::
|
|
|
|
-H::
|
2006-09-16 05:37:01 +04:00
|
|
|
By default, the command shows the filename for each
|
|
|
|
match. `-h` option is used to suppress this output.
|
|
|
|
`-H` is there for completeness and does not do anything
|
|
|
|
except it overrides `-h` given earlier on the command
|
|
|
|
line.
|
|
|
|
|
2006-08-11 11:44:42 +04:00
|
|
|
--full-name::
|
|
|
|
When run from a subdirectory, the command usually
|
|
|
|
outputs paths relative to the current directory. This
|
|
|
|
option forces paths to be output relative to the project
|
|
|
|
top directory.
|
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
-E::
|
|
|
|
--extended-regexp::
|
|
|
|
-G::
|
|
|
|
--basic-regexp::
|
2006-05-09 00:28:49 +04:00
|
|
|
Use POSIX extended/basic regexp for patterns. Default
|
|
|
|
is to use basic regexp.
|
2006-01-21 02:00:12 +03:00
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
-F::
|
|
|
|
--fixed-strings::
|
2007-04-27 08:58:58 +04:00
|
|
|
Use fixed strings for patterns (don't interpret pattern
|
|
|
|
as a regex).
|
|
|
|
|
2006-05-09 00:28:49 +04:00
|
|
|
-n::
|
|
|
|
Prefix the line number to matching lines.
|
2005-09-13 06:39:15 +04:00
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
-l::
|
|
|
|
--files-with-matches::
|
|
|
|
--name-only::
|
|
|
|
-L::
|
|
|
|
--files-without-match::
|
2006-05-09 00:28:49 +04:00
|
|
|
Instead of showing every matched line, show only the
|
|
|
|
names of files that contain (or do not contain) matches.
|
2008-07-03 09:41:41 +04:00
|
|
|
For better compatibility with 'git-diff', --name-only is a
|
2008-02-21 07:28:07 +03:00
|
|
|
synonym for --files-with-matches.
|
2005-09-13 06:39:15 +04:00
|
|
|
|
2008-10-01 20:11:15 +04:00
|
|
|
-z::
|
|
|
|
--null::
|
|
|
|
Output \0 instead of the character that normally follows a
|
|
|
|
file name.
|
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
-c::
|
|
|
|
--count::
|
2006-05-09 00:28:49 +04:00
|
|
|
Instead of showing every matched line, show the number of
|
|
|
|
lines that match.
|
|
|
|
|
|
|
|
-[ABC] <context>::
|
|
|
|
Show `context` trailing (`A` -- after), or leading (`B`
|
|
|
|
-- before), or both (`C` -- context) lines, and place a
|
2006-06-04 00:27:26 +04:00
|
|
|
line containing `--` between contiguous groups of
|
2006-05-09 00:28:49 +04:00
|
|
|
matches.
|
|
|
|
|
2007-04-27 08:58:58 +04:00
|
|
|
-<num>::
|
|
|
|
A shortcut for specifying -C<num>.
|
|
|
|
|
2006-05-09 00:28:49 +04:00
|
|
|
-f <file>::
|
|
|
|
Read patterns from <file>, one per line.
|
|
|
|
|
2006-06-25 20:07:15 +04:00
|
|
|
-e::
|
|
|
|
The next parameter is the pattern. This option has to be
|
|
|
|
used for patterns starting with - and should be used in
|
2006-08-03 02:04:56 +04:00
|
|
|
scripts passing user input to grep. Multiple patterns are
|
|
|
|
combined by 'or'.
|
|
|
|
|
2008-06-08 05:36:09 +04:00
|
|
|
--and::
|
|
|
|
--or::
|
|
|
|
--not::
|
|
|
|
( ... )::
|
2007-01-17 18:32:41 +03:00
|
|
|
Specify how multiple patterns are combined using Boolean
|
2006-08-03 02:04:56 +04:00
|
|
|
expressions. `--or` is the default operator. `--and` has
|
|
|
|
higher precedence than `--or`. `-e` has to be used for all
|
|
|
|
patterns.
|
2006-06-25 20:07:15 +04:00
|
|
|
|
2006-09-28 04:50:52 +04:00
|
|
|
--all-match::
|
|
|
|
When giving multiple pattern expressions combined with `--or`,
|
|
|
|
this flag is specified to limit the match to files that
|
|
|
|
have lines to match all of them.
|
|
|
|
|
2006-05-09 00:28:49 +04:00
|
|
|
`<tree>...`::
|
|
|
|
Search blobs in the trees for specified patterns.
|
|
|
|
|
2006-08-03 02:04:56 +04:00
|
|
|
\--::
|
2006-05-09 00:28:49 +04:00
|
|
|
Signals the end of options; the rest of the parameters
|
|
|
|
are <path> limiters.
|
2005-09-13 06:39:15 +04:00
|
|
|
|
|
|
|
|
2006-08-03 02:04:56 +04:00
|
|
|
Example
|
|
|
|
-------
|
|
|
|
|
|
|
|
git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
|
|
|
|
Looks for a line that has `#define` and either `MAX_PATH` or
|
|
|
|
`PATH_MAX`.
|
|
|
|
|
2006-09-28 04:50:52 +04:00
|
|
|
git grep --all-match -e NODE -e Unexpected::
|
|
|
|
Looks for a line that has `NODE` or `Unexpected` in
|
|
|
|
files that have lines that match both.
|
|
|
|
|
2005-09-13 06:39:15 +04:00
|
|
|
Author
|
|
|
|
------
|
2006-05-09 00:28:49 +04:00
|
|
|
Originally written by Linus Torvalds <torvalds@osdl.org>, later
|
|
|
|
revamped by Junio C Hamano.
|
|
|
|
|
2005-09-13 06:39:15 +04:00
|
|
|
|
|
|
|
Documentation
|
|
|
|
--------------
|
|
|
|
Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
|
|
|
|
|
|
|
|
GIT
|
|
|
|
---
|
2008-06-06 11:07:32 +04:00
|
|
|
Part of the linkgit:git[1] suite
|