table of contents
GIT-GREP(1) | Git Manual | GIT-GREP(1) |
NAME¶
git-grep - Print lines matching a pattern
SYNOPSIS¶
git grep [-a | --text] [-I] [--textconv] [-i | --ignore-case] [-w | --word-regexp]
[-v | --invert-match] [-h|-H] [--full-name]
[-E | --extended-regexp] [-G | --basic-regexp]
[-P | --perl-regexp]
[-F | --fixed-strings] [-n | --line-number] [--column]
[-l | --files-with-matches] [-L | --files-without-match]
[(-O | --open-files-in-pager) [<pager>]]
[-z | --null]
[ -o | --only-matching ] [-c | --count] [--all-match] [-q | --quiet]
[--max-depth <depth>] [--[no-]recursive]
[--color[=<when>] | --no-color]
[--break] [--heading] [-p | --show-function]
[-A <post-context>] [-B <pre-context>] [-C <context>]
[-W | --function-context]
[(-m | --max-count) <num>]
[--threads <num>]
[-f <file>] [-e] <pattern>
[--and|--or|--not|(|)|-e <pattern>...]
[--recurse-submodules] [--parent-basename <basename>]
[ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | <tree>...]
[--] [<pathspec>...]
DESCRIPTION¶
Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects. Patterns are lists of one or more search expressions separated by newline characters. An empty string as search expression matches all lines.
OPTIONS¶
--cached
--no-index
--untracked
--no-exclude-standard
--exclude-standard
--recurse-submodules
-a, --text
--textconv
--no-textconv
-i, --ignore-case
-I
--max-depth <depth>
-r, --recursive
--no-recursive
-w, --word-regexp
-v, --invert-match
-h, -H
--full-name
-E, --extended-regexp, -G, --basic-regexp
-P, --perl-regexp
Support for these types of regular expressions is an optional compile-time dependency. If Git wasn’t compiled with support for them providing this option will cause it to die.
-F, --fixed-strings
-n, --line-number
--column
-l, --files-with-matches, --name-only, -L, --files-without-match
-O[<pager>], --open-files-in-pager[=<pager>]
-z, --null
-o, --only-matching
-c, --count
--color[=<when>]
--no-color
--break
--heading
-p, --show-function
-<num>, -C <num>, --context <num>
-A <num>, --after-context <num>
-B <num>, --before-context <num>
-W, --function-context
-m <num>, --max-count <num>
--threads <num>
-f <file>
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
--and, --or, --not, ( ... )
--all-match
-q, --quiet
<tree>...
--
<pathspec>...
For more details about the <pathspec> syntax, see the pathspec entry in gitglossary(7).
EXAMPLES¶
git grep 'time_t' -- '*.[ch]'
git grep -e '#define' --and \( -e MAX_PATH -e PATH_MAX \)
git grep --all-match -e NODE -e Unexpected
git grep solution -- :^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. So if you experience low performance in this case, it might be desirable to use --threads=1.
CONFIGURATION¶
Everything below this line in this section is selectively included from the git-config(1) documentation. The content is the same as what’s found there:
grep.lineNumber
grep.column
grep.patternType
grep.extendedRegexp
grep.threads
grep.fullName
grep.fallbackToNoIndex
GIT¶
Part of the git(1) suite
11/20/2023 | Git 2.43.0 |