git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv2] grep documentation: clarify what files match

From
Mark Lodato <lodatom@gmail.com>
Date
Feb 16, 2010, 00:25 UTC
Message-ID
<1266279940-13251-1-git-send-email-lodatom@gmail.com>
In-Reply-To
<7vvddz5l1z.fsf@alter.siamese.dyndns.org>

Clarify that git-grep(1) searches only tracked files, and that each <path> is a glob, as in git-add(1). Add an example to show a simple use case for searching all .c and .h files.

The meta-variable <path> should be changed to an official term for a path glob, and the description for this should be in git(1), not git-add(1). However, we don't yet have such an official term, so just use <path> and reference git-add(1) for now.

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---
 Documentation/git-grep.txt |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index e019e76..7f24032 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -26,8 +26,8 @@ SYNOPSIS
 
 DESCRIPTION
 -----------
-Look for specified patterns in the working tree files, blobs
-registered in the index file, or given tree objects.
+Look for specified patterns in the tracked files in the working tree, blobs
+registered in the index file, or blobs in given tree objects.
 
 
 OPTIONS
@@ -49,7 +49,7 @@ OPTIONS
 	Don't match the pattern in binary files.
 
 --max-depth <depth>::
-	For each pathspec given on command line, descend at most <depth>
+	For each <path> given on command line, descend at most <depth>
 	levels of directories. A negative value means no limit.
 
 -w::
@@ -170,10 +170,17 @@ OPTIONS
 	Signals the end of options; the rest of the parameters
 	are <path> limiters.
 
+<path>...::
+	If given, limit the search to paths matching at least one pattern.
+	Each pattern is the same as <filepattern> of linkgit:git-add[1].
 
 Example
 -------
 
+git grep 'time_t' -- '*.[ch]'::
+	Looks for `time_t` in all tracked .c and .h files in the working
+	directory.
+
 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`.
-- 
1.7.0
Previous: Mark LodatoNext: Junio C Hamano
Message 4 of 5 in “git-grep ignores untracked files”
  1. Mark LodatoFeb 15, 2010
  2. Junio C HamanoFeb 15, 2010
  3. Mark LodatoFeb 16, 2010
  4. [PATCHv2] grep documentation: clarify what files matchMark Lodato, Feb 16, 2010
  5. Junio C HamanoFeb 16, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.