Skip to content

Commit 3ac4440

Browse files
MarkLodatogitster
authored andcommitted
grep documentation: clarify what files match
Clarify that git-grep(1) searches only tracked files, and that each <pathspec> is a pathspec, as in any other ordinary git commands. Add an example to show a simple use case for searching all .c and .h files in the current directory and below. Signed-off-by: Mark Lodato <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ef00650 commit 3ac4440

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Documentation/git-grep.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ SYNOPSIS
2222
[-A <post-context>] [-B <pre-context>] [-C <context>]
2323
[-f <file>] [-e] <pattern>
2424
[--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
25-
[--] [<path>...]
25+
[--] [<pathspec>...]
2626

2727
DESCRIPTION
2828
-----------
29-
Look for specified patterns in the working tree files, blobs
30-
registered in the index file, or given tree objects.
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.
3131

3232

3333
OPTIONS
@@ -49,7 +49,7 @@ OPTIONS
4949
Don't match the pattern in binary files.
5050

5151
--max-depth <depth>::
52-
For each pathspec given on command line, descend at most <depth>
52+
For each <pathspec> given on command line, descend at most <depth>
5353
levels of directories. A negative value means no limit.
5454

5555
-w::
@@ -163,12 +163,19 @@ OPTIONS
163163

164164
\--::
165165
Signals the end of options; the rest of the parameters
166-
are <path> limiters.
166+
are <pathspec> limiters.
167167

168+
<pathspec>...::
169+
If given, limit the search to paths matching at least one pattern.
170+
Both leading paths match and glob(7) patterns are supported.
168171

169172
Example
170173
-------
171174

175+
git grep 'time_t' -- '*.[ch]'::
176+
Looks for `time_t` in all tracked .c and .h files in the working
177+
directory and its subdirectories.
178+
172179
git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
173180
Looks for a line that has `#define` and either `MAX_PATH` or
174181
`PATH_MAX`.

0 commit comments

Comments
 (0)