Home Explore Blog CI



git

4th chunk of `Documentation/git-grep.adoc`
3e76d8676da58e3f235d60201772cbb570ccb58adf12ae420000000100000e4a
 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, there were also
odd and undocumented interactions between e.g. non-ASCII patterns
containing \0 and `--ignore-case`.
+
In future versions we may learn to support patterns containing \0 for
more search backends, until then we'll die when the pattern type in
question doesn't support them.

-e::
	The next parameter is the pattern. This option has to be
	used for patterns starting with `-` and should be used in
	scripts passing user input to grep.  Multiple patterns are
	combined by 'or'.

--and::
--or::
--not::
( ... )::
	Specify how multiple patterns are combined using Boolean
	expressions.  `--or` is the default operator.  `--and` has
	higher precedence than `--or`.  `-e` has to be used for all
	patterns.

--all-match::
	When giving multiple pattern expressions combined with `--or`,
	this flag is specified to limit the match to files that
	have lines to match all of them.

-q::
--quiet::
	Do not output matched lines; instead, exit with status 0 when
	there is a match and with non-zero status when there isn't.

<tree>...::
	Instead of searching tracked files in the working tree, search
	blobs in the given trees.

\--::
	Signals the end of options; the rest of the parameters
	are <pathspec> limiters.

<pathspec>...::
	If given, limit the search to paths matching at least one pattern.
	Both leading paths match and glob(7) patterns are supported.
+
For more details about the <pathspec> syntax, see the 'pathspec' entry
in linkgit:gitglossary[7].

EXAMPLES
--------

`git grep 'time_t' -- '*.[ch]'`::
	Looks for `time_t` in all tracked .c and .h files in the working
	directory and its subdirectories.

`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`.

`git grep --all-match -e NODE -e Unexpected`::
	Looks for a line that has `NODE` or `Unexpected` in
	files that have lines that match both.

`git grep solution -- :^Documentation`::
	Looks for `solution`, excluding files in `Documentation`.

NOTES ON THREADS
----------------

The `--threads` option (and the `grep.threads` configuration) will be ignored when
`--open-files-in-pager` is used, forcing a single-threaded execution.

When grepping the object store (with `--cached` or giving tree objects), running
with multiple threads might perform slower than single-threaded if `--textconv`
is given and there are too many text conversions.  Thus, if low performance is
experienced in this case, it might be desirable to use `--threads=1`.

CONFIGURATION
-------------

include::includes/cmd-config-section-all.adoc[]

include::config/grep.adoc[]

GIT
---
Part of the linkgit:git[1] suite

Title: Git Grep Command Options and Configuration
Summary
The git grep command provides various options for searching patterns in files, including limiting matches, using threads, and specifying Boolean expressions, as well as configuration options for customizing its behavior, such as setting the number of threads and specifying text conversion settings.