Home Explore Blog CI



git

3rd chunk of `Documentation/git-grep.adoc`
793240783210d9203c59df61292e3ae5aa276006f1c212890000000100000a5b
 of a matching line, with each such
	part on a separate output line.

-c::
--count::
	Instead of showing every matched line, show the number of
	lines that match.

--color[=<when>]::
	Show colored matches.
	The value must be always (the default), never, or auto.

--no-color::
	Turn off match highlighting, even when the configuration file
	gives the default to color output.
	Same as `--color=never`.

--break::
	Print an empty line between matches from different files.

--heading::
	Show the filename above the matches in that file instead of
	at the start of each shown line.

-p::
--show-function::
	Show the preceding line that contains the function name of
	the match, unless the matching line is a function name itself.
	The name is determined in the same way as `git diff` works out
	patch hunk headers (see 'Defining a custom hunk-header' in
	linkgit:gitattributes[5]).

-<num>::
-C <num>::
--context <num>::
	Show <num> leading and trailing lines, and place a line
	containing `--` between contiguous groups of matches.

-A <num>::
--after-context <num>::
	Show <num> trailing lines, and place a line containing
	`--` between contiguous groups of matches.

-B <num>::
--before-context <num>::
	Show <num> leading lines, and place a line containing
	`--` between contiguous groups of matches.

-W::
--function-context::
	Show the surrounding text from the previous line containing a
	function name up to the one before the next function name,
	effectively showing the whole function in which the match was
	found. The function names are determined in the same way as
	`git diff` works out patch hunk headers (see 'Defining a
	custom hunk-header' in linkgit:gitattributes[5]).

-m <num>::
--max-count <num>::
	Limit the amount of matches per file. When using the `-v` or
	`--invert-match` option, the search stops after the specified
	number of non-matches. A value of -1 will return unlimited
	results (the default). A value of 0 will exit immediately with
	a non-zero status.

--threads <num>::
	Number of `grep` worker threads to use.  See 'NOTES ON THREADS'
	and `grep.threads` in 'CONFIGURATION' for more information.

-f <file>::
	Read patterns from <file>, one per line.
+
Passing the pattern via <file> allows for providing a search pattern
containing a \0.
+
Not all pattern types support patterns containing \0. Git will error
out if a given pattern type can't support such a pattern. The
`--perl-regexp` pattern type when compiled against the PCRE v2 backend
has the widest support for these types of patterns.
+
In versions of Git before 2.23.0 patterns containing \0 would be
silently considered fixed. This was never documented,

Title: Advanced Git Grep Options
Summary
The git-grep command provides additional options for customizing the search, including showing match counts, coloring matches, and displaying context lines, as well as options for limiting the number of matches, using multiple threads, and reading patterns from a file.