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

[PATCH v2] Teach git-grep --name-only as synonym for -l

From
Shawn O. Pearce <spearce@spearce.org>
Date
Feb 21, 2008, 04:28 UTC
Message-ID
<20080221042807.GA3235@spearce.org>

I expected git grep --name-only to give me only the file names, much as git diff --name-only only generates filenames. Alas the option is -l, which matches common external greps but doesn't match other parts of the git UI.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 This time with documentation!
 Documentation/git-grep.txt |    4 +++-
 builtin-grep.c             |    1 +
 2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index f3cb24f..71a7335 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -75,9 +75,11 @@ OPTIONS
 -n::
 	Prefix the line number to matching lines.
 
--l | --files-with-matches | -L | --files-without-match::
+-l | --files-with-matches | --name-only | -L | --files-without-match::
 	Instead of showing every matched line, show only the
 	names of files that contain (or do not contain) matches.
+	For better compatability with git-diff, --name-only is a
+	synonym for --files-with-matches.
 
 -c | --count::
 	Instead of showing every matched line, show the number of
diff --git a/builtin-grep.c b/builtin-grep.c
index 9180b39..f4f4ecb 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -578,6 +578,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 		if (!strcmp("-l", arg) ||
+		    !strcmp("--name-only", arg) ||
 		    !strcmp("--files-with-matches", arg)) {
 			opt.name_only = 1;
 			continue;
-- 
1.5.4.2.232.g08e5
Message 1 of 1 in “Teach git-grep --name-only as synonym for -l”
  1. Teach git-grep --name-only as synonym for -lShawn O. Pearce, Feb 21, 2008

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.