path: root/Documentation/git-grep.txt
diff options
authorTaylor Blau <>2018-07-09 20:33:47 (GMT)
committerJunio C Hamano <>2018-07-09 21:15:28 (GMT)
commit9d8db06eb4a5d5577db559a0059a377914c1ce5a (patch)
treea0ef841c1f6cd361d25b5c9f0e25337eb4a1c38d /Documentation/git-grep.txt
parentc707ded332375a5b51c1acf9b7ce1c29cbd4536d (diff)
grep.c: teach 'git grep --only-matching'
Teach 'git grep --only-matching', a new option to only print the matching part(s) of a line. For instance, a line containing the following (taken from (`man gitcvs-migration` or `git help cvs-migration` if git is Is printed as follows: $ git grep --line-number --column --only-matching -e git -- \ | grep ":27" The patch works mostly as one would expect, with the exception of a few considerations that are worth mentioning here. Like GNU grep, this patch ignores --only-matching when --invert (-v) is given. There is a sensible answer here, but parity with the behavior of other tools is preferred. Because a line might contain more than one match, there are special considerations pertaining to when to print line headers, newlines, and how to increment the match column offset. The line header and newlines are handled as a special case within the main loop to avoid polluting the surrounding code with conditionals that have large blocks. Signed-off-by: Taylor Blau <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'Documentation/git-grep.txt')
1 files changed, 6 insertions, 1 deletions
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index 0de3493..a3049af 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -17,7 +17,7 @@ SYNOPSIS
[-l | --files-with-matches] [-L | --files-without-match]
[(-O | --open-files-in-pager) [<pager>]]
[-z | --null]
- [-c | --count] [--all-match] [-q | --quiet]
+ [ -o | --only-matching ] [-c | --count] [--all-match] [-q | --quiet]
[--max-depth <depth>]
[--color[=<when>] | --no-color]
[--break] [--heading] [-p | --show-function]
@@ -201,6 +201,11 @@ providing this option will cause it to die.
Output \0 instead of the character that normally follows a
file name.
+ Print only the matched (non-empty) parts of a matching line, with each such
+ part on a separate output line.
Instead of showing every matched line, show the number of