| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-grep(1) | 
|  | 2 | =========== | 
|  | 3 |  | 
|  | 4 | NAME | 
|  | 5 | ---- | 
| Junio C Hamano | 0107892 | 2006-03-10 00:31:47 | [diff] [blame] | 6 | git-grep - Print lines matching a pattern | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 |  | 
|  | 8 |  | 
|  | 9 | SYNOPSIS | 
|  | 10 | -------- | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 11 | [verse] | 
| Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 12 | 'git grep' [--cached] | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 13 | [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp] | 
| Junio C Hamano | 97efb00 | 2006-09-16 18:16:04 | [diff] [blame] | 14 | [-v | --invert-match] [-h|-H] [--full-name] | 
| Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 15 | [-E | --extended-regexp] [-G | --basic-regexp] | 
|  | 16 | [-F | --fixed-strings] [-n] | 
|  | 17 | [-l | --files-with-matches] [-L | --files-without-match] | 
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 18 | [-z | --null] | 
| Junio C Hamano | 83b3547 | 2010-01-29 05:02:13 | [diff] [blame] | 19 | [-c | --count] [--all-match] [-q | --quiet] | 
| Junio C Hamano | 9f88386 | 2009-08-11 06:23:52 | [diff] [blame] | 20 | [--max-depth <depth>] | 
| Junio C Hamano | d257cff | 2009-03-18 05:27:16 | [diff] [blame] | 21 | [--color | --no-color] | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 22 | [-A <post-context>] [-B <pre-context>] [-C <context>] | 
| Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 23 | [-f <file>] [-e] <pattern> | 
|  | 24 | [--and|--or|--not|(|)|-e <pattern>...] [<tree>...] | 
| Junio C Hamano | 74a198f | 2010-02-22 00:13:31 | [diff] [blame^] | 25 | [--] [<pathspec>...] | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 26 |  | 
|  | 27 | DESCRIPTION | 
|  | 28 | ----------- | 
| Junio C Hamano | 74a198f | 2010-02-22 00:13:31 | [diff] [blame^] | 29 | Look for specified patterns in the tracked files in the work tree, blobs | 
|  | 30 | registered in the index file, or blobs in given tree objects. | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 31 |  | 
|  | 32 |  | 
|  | 33 | OPTIONS | 
|  | 34 | ------- | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 35 | --cached:: | 
|  | 36 | Instead of searching in the working tree files, check | 
| Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 37 | the blobs registered in the index file. | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 38 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 39 | -a:: | 
|  | 40 | --text:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 41 | Process binary files as if they were text. | 
|  | 42 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 43 | -i:: | 
|  | 44 | --ignore-case:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 45 | Ignore case differences between the patterns and the | 
|  | 46 | files. | 
|  | 47 |  | 
| Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 48 | -I:: | 
|  | 49 | Don't match the pattern in binary files. | 
|  | 50 |  | 
| Junio C Hamano | 9f88386 | 2009-08-11 06:23:52 | [diff] [blame] | 51 | --max-depth <depth>:: | 
| Junio C Hamano | 74a198f | 2010-02-22 00:13:31 | [diff] [blame^] | 52 | For each <pathspec> given on command line, descend at most <depth> | 
| Junio C Hamano | 9f88386 | 2009-08-11 06:23:52 | [diff] [blame] | 53 | levels of directories. A negative value means no limit. | 
|  | 54 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 55 | -w:: | 
|  | 56 | --word-regexp:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 57 | Match the pattern only at word boundary (either begin at the | 
|  | 58 | beginning of a line, or preceded by a non-word character; end at | 
|  | 59 | the end of a line or followed by a non-word character). | 
|  | 60 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 61 | -v:: | 
|  | 62 | --invert-match:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 63 | Select non-matching lines. | 
|  | 64 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 65 | -h:: | 
|  | 66 | -H:: | 
| Junio C Hamano | 97efb00 | 2006-09-16 18:16:04 | [diff] [blame] | 67 | By default, the command shows the filename for each | 
|  | 68 | match. `-h` option is used to suppress this output. | 
|  | 69 | `-H` is there for completeness and does not do anything | 
|  | 70 | except it overrides `-h` given earlier on the command | 
|  | 71 | line. | 
|  | 72 |  | 
| Junio C Hamano | 85e45fa | 2006-08-13 07:47:41 | [diff] [blame] | 73 | --full-name:: | 
|  | 74 | When run from a subdirectory, the command usually | 
|  | 75 | outputs paths relative to the current directory. This | 
|  | 76 | option forces paths to be output relative to the project | 
|  | 77 | top directory. | 
|  | 78 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 79 | -E:: | 
|  | 80 | --extended-regexp:: | 
|  | 81 | -G:: | 
|  | 82 | --basic-regexp:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 83 | Use POSIX extended/basic regexp for patterns. Default | 
|  | 84 | is to use basic regexp. | 
|  | 85 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 86 | -F:: | 
|  | 87 | --fixed-strings:: | 
| Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 88 | Use fixed strings for patterns (don't interpret pattern | 
|  | 89 | as a regex). | 
|  | 90 |  | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 91 | -n:: | 
|  | 92 | Prefix the line number to matching lines. | 
|  | 93 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 94 | -l:: | 
|  | 95 | --files-with-matches:: | 
|  | 96 | --name-only:: | 
|  | 97 | -L:: | 
|  | 98 | --files-without-match:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 99 | Instead of showing every matched line, show only the | 
|  | 100 | names of files that contain (or do not contain) matches. | 
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 101 | For better compatibility with 'git diff', --name-only is a | 
| Junio C Hamano | 074766f | 2008-02-22 22:57:06 | [diff] [blame] | 102 | synonym for --files-with-matches. | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 103 |  | 
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 104 | -z:: | 
|  | 105 | --null:: | 
|  | 106 | Output \0 instead of the character that normally follows a | 
|  | 107 | file name. | 
|  | 108 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 109 | -c:: | 
|  | 110 | --count:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 111 | Instead of showing every matched line, show the number of | 
|  | 112 | lines that match. | 
|  | 113 |  | 
| Junio C Hamano | d257cff | 2009-03-18 05:27:16 | [diff] [blame] | 114 | --color:: | 
|  | 115 | Show colored matches. | 
|  | 116 |  | 
|  | 117 | --no-color:: | 
|  | 118 | Turn off match highlighting, even when the configuration file | 
|  | 119 | gives the default to color output. | 
|  | 120 |  | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 121 | -[ABC] <context>:: | 
|  | 122 | Show `context` trailing (`A` -- after), or leading (`B` | 
|  | 123 | -- before), or both (`C` -- context) lines, and place a | 
| Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 124 | line containing `--` between contiguous groups of | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 125 | matches. | 
|  | 126 |  | 
| Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 127 | -<num>:: | 
|  | 128 | A shortcut for specifying -C<num>. | 
|  | 129 |  | 
| Junio C Hamano | 48bc1ce | 2009-07-09 16:49:19 | [diff] [blame] | 130 | -p:: | 
|  | 131 | --show-function:: | 
|  | 132 | Show the preceding line that contains the function name of | 
|  | 133 | the match, unless the matching line is a function name itself. | 
|  | 134 | The name is determined in the same way as 'git diff' works out | 
|  | 135 | patch hunk headers (see 'Defining a custom hunk-header' in | 
|  | 136 | linkgit:gitattributes[5]). | 
|  | 137 |  | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 138 | -f <file>:: | 
|  | 139 | Read patterns from <file>, one per line. | 
|  | 140 |  | 
| Junio C Hamano | 3901ffb | 2006-06-26 23:46:53 | [diff] [blame] | 141 | -e:: | 
|  | 142 | The next parameter is the pattern. This option has to be | 
|  | 143 | used for patterns starting with - and should be used in | 
| Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 144 | scripts passing user input to grep. Multiple patterns are | 
|  | 145 | combined by 'or'. | 
|  | 146 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 147 | --and:: | 
|  | 148 | --or:: | 
|  | 149 | --not:: | 
|  | 150 | ( ... ):: | 
| Junio C Hamano | f9771f6 | 2007-01-17 17:42:30 | [diff] [blame] | 151 | Specify how multiple patterns are combined using Boolean | 
| Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 152 | expressions. `--or` is the default operator. `--and` has | 
|  | 153 | higher precedence than `--or`. `-e` has to be used for all | 
|  | 154 | patterns. | 
| Junio C Hamano | 3901ffb | 2006-06-26 23:46:53 | [diff] [blame] | 155 |  | 
| Junio C Hamano | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 156 | --all-match:: | 
|  | 157 | When giving multiple pattern expressions combined with `--or`, | 
|  | 158 | this flag is specified to limit the match to files that | 
|  | 159 | have lines to match all of them. | 
|  | 160 |  | 
| Junio C Hamano | 83b3547 | 2010-01-29 05:02:13 | [diff] [blame] | 161 | -q:: | 
|  | 162 | --quiet:: | 
|  | 163 | Do not output matched lines; instead, exit with status 0 when | 
|  | 164 | there is a match and with non-zero status when there isn't. | 
|  | 165 |  | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 166 | `<tree>...`:: | 
|  | 167 | Search blobs in the trees for specified patterns. | 
|  | 168 |  | 
| Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 169 | \--:: | 
| Junio C Hamano | a6331a8 | 2006-01-22 07:50:33 | [diff] [blame] | 170 | Signals the end of options; the rest of the parameters | 
| Junio C Hamano | 74a198f | 2010-02-22 00:13:31 | [diff] [blame^] | 171 | are <pathspec> limiters. | 
| Junio C Hamano | a6331a8 | 2006-01-22 07:50:33 | [diff] [blame] | 172 |  | 
| Junio C Hamano | 74a198f | 2010-02-22 00:13:31 | [diff] [blame^] | 173 | <pathspec>...:: | 
|  | 174 | If given, limit the search to paths matching at least one pattern. | 
|  | 175 | Both leading paths match and glob(7) patterns are supported. | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 176 |  | 
| Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 177 | Example | 
|  | 178 | ------- | 
|  | 179 |  | 
| Junio C Hamano | 74a198f | 2010-02-22 00:13:31 | [diff] [blame^] | 180 | git grep 'time_t' -- '*.[ch]':: | 
|  | 181 | Looks for `time_t` in all tracked .c and .h files in the working | 
|  | 182 | directory and its subdirectories. | 
|  | 183 |  | 
| Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 184 | git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \):: | 
|  | 185 | Looks for a line that has `#define` and either `MAX_PATH` or | 
|  | 186 | `PATH_MAX`. | 
|  | 187 |  | 
| Junio C Hamano | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 188 | git grep --all-match -e NODE -e Unexpected:: | 
|  | 189 | Looks for a line that has `NODE` or `Unexpected` in | 
|  | 190 | files that have lines that match both. | 
|  | 191 |  | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 192 | Author | 
|  | 193 | ------ | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 194 | Originally written by Linus Torvalds <torvalds@osdl.org>, later | 
|  | 195 | revamped by Junio C Hamano. | 
|  | 196 |  | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 197 |  | 
|  | 198 | Documentation | 
|  | 199 | -------------- | 
|  | 200 | Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. | 
|  | 201 |  | 
|  | 202 | GIT | 
|  | 203 | --- | 
| Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 204 | Part of the linkgit:git[1] suite |