]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-grep.txt
documentation: move git(7) to git(1)
[thirdparty/git.git] / Documentation / git-grep.txt
CommitLineData
2aba319a
JH
1git-grep(1)
2===========
2aba319a
JH
3
4NAME
5----
5001422d 6git-grep - Print lines matching a pattern
2aba319a
JH
7
8
9SYNOPSIS
10--------
1c57119c
JH
11[verse]
12'git-grep' [--cached]
13 [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
17fd965d 14 [-v | --invert-match] [-h|-H] [--full-name]
cf0d720b
AR
15 [-E | --extended-regexp] [-G | --basic-regexp]
16 [-F | --fixed-strings] [-n]
17 [-l | --files-with-matches] [-L | --files-without-match]
0ab7befa 18 [-c | --count] [--all-match]
1c57119c 19 [-A <post-context>] [-B <pre-context>] [-C <context>]
cf0d720b
AR
20 [-f <file>] [-e] <pattern>
21 [--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
1c57119c 22 [--] [<path>...]
2aba319a
JH
23
24DESCRIPTION
25-----------
1c57119c
JH
26Look for specified patterns in the working tree files, blobs
27registered in the index file, or given tree objects.
2aba319a
JH
28
29
30OPTIONS
31-------
1c57119c
JH
32--cached::
33 Instead of searching in the working tree files, check
abda1ef5 34 the blobs registered in the index file.
1c57119c
JH
35
36-a | --text::
37 Process binary files as if they were text.
38
39-i | --ignore-case::
40 Ignore case differences between the patterns and the
41 files.
42
cf0d720b
AR
43-I::
44 Don't match the pattern in binary files.
45
1c57119c
JH
46-w | --word-regexp::
47 Match the pattern only at word boundary (either begin at the
48 beginning of a line, or preceded by a non-word character; end at
49 the end of a line or followed by a non-word character).
50
51-v | --invert-match::
52 Select non-matching lines.
53
17fd965d
JH
54-h | -H::
55 By default, the command shows the filename for each
56 match. `-h` option is used to suppress this output.
57 `-H` is there for completeness and does not do anything
58 except it overrides `-h` given earlier on the command
59 line.
60
0d042fec
JH
61--full-name::
62 When run from a subdirectory, the command usually
63 outputs paths relative to the current directory. This
64 option forces paths to be output relative to the project
65 top directory.
66
1c57119c
JH
67-E | --extended-regexp | -G | --basic-regexp::
68 Use POSIX extended/basic regexp for patterns. Default
69 is to use basic regexp.
5b2bcc7b 70
cf0d720b
AR
71-F | --fixed-strings::
72 Use fixed strings for patterns (don't interpret pattern
73 as a regex).
74
1c57119c
JH
75-n::
76 Prefix the line number to matching lines.
2aba319a 77
2cd5dfd2 78-l | --files-with-matches | --name-only | -L | --files-without-match::
1c57119c
JH
79 Instead of showing every matched line, show only the
80 names of files that contain (or do not contain) matches.
34cd62eb 81 For better compatibility with git-diff, --name-only is a
2cd5dfd2 82 synonym for --files-with-matches.
2aba319a 83
1c57119c
JH
84-c | --count::
85 Instead of showing every matched line, show the number of
86 lines that match.
87
88-[ABC] <context>::
89 Show `context` trailing (`A` -- after), or leading (`B`
90 -- before), or both (`C` -- context) lines, and place a
abda1ef5 91 line containing `--` between contiguous groups of
1c57119c
JH
92 matches.
93
cf0d720b
AR
94-<num>::
95 A shortcut for specifying -C<num>.
96
1c57119c
JH
97-f <file>::
98 Read patterns from <file>, one per line.
99
3acb27b6
ML
100-e::
101 The next parameter is the pattern. This option has to be
102 used for patterns starting with - and should be used in
fba0cbd9
ML
103 scripts passing user input to grep. Multiple patterns are
104 combined by 'or'.
105
106--and | --or | --not | ( | )::
23bfbb81 107 Specify how multiple patterns are combined using Boolean
fba0cbd9
ML
108 expressions. `--or` is the default operator. `--and` has
109 higher precedence than `--or`. `-e` has to be used for all
110 patterns.
3acb27b6 111
0ab7befa
JH
112--all-match::
113 When giving multiple pattern expressions combined with `--or`,
114 this flag is specified to limit the match to files that
115 have lines to match all of them.
116
1c57119c
JH
117`<tree>...`::
118 Search blobs in the trees for specified patterns.
119
fba0cbd9 120\--::
1c57119c
JH
121 Signals the end of options; the rest of the parameters
122 are <path> limiters.
2aba319a
JH
123
124
fba0cbd9
ML
125Example
126-------
127
128git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
129 Looks for a line that has `#define` and either `MAX_PATH` or
130 `PATH_MAX`.
131
0ab7befa
JH
132git grep --all-match -e NODE -e Unexpected::
133 Looks for a line that has `NODE` or `Unexpected` in
134 files that have lines that match both.
135
2aba319a
JH
136Author
137------
1c57119c
JH
138Originally written by Linus Torvalds <torvalds@osdl.org>, later
139revamped by Junio C Hamano.
140
2aba319a
JH
141
142Documentation
143--------------
144Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
145
146GIT
147---
9e1f0a85 148Part of the linkgit:git[1] suite