| 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 | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 19 | [-c | --count] [--all-match] | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 20 | [-A <post-context>] [-B <pre-context>] [-C <context>] | 
| Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 21 | [-f <file>] [-e] <pattern> | 
|  | 22 | [--and|--or|--not|(|)|-e <pattern>...] [<tree>...] | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 23 | [--] [<path>...] | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 24 |  | 
|  | 25 | DESCRIPTION | 
|  | 26 | ----------- | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 27 | Look for specified patterns in the working tree files, blobs | 
|  | 28 | registered in the index file, or given tree objects. | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 29 |  | 
|  | 30 |  | 
|  | 31 | OPTIONS | 
|  | 32 | ------- | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 33 | --cached:: | 
|  | 34 | Instead of searching in the working tree files, check | 
| Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 35 | the blobs registered in the index file. | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 36 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 37 | -a:: | 
|  | 38 | --text:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 39 | Process binary files as if they were text. | 
|  | 40 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 41 | -i:: | 
|  | 42 | --ignore-case:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 43 | Ignore case differences between the patterns and the | 
|  | 44 | files. | 
|  | 45 |  | 
| Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 46 | -I:: | 
|  | 47 | Don't match the pattern in binary files. | 
|  | 48 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 49 | -w:: | 
|  | 50 | --word-regexp:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 51 | Match the pattern only at word boundary (either begin at the | 
|  | 52 | beginning of a line, or preceded by a non-word character; end at | 
|  | 53 | the end of a line or followed by a non-word character). | 
|  | 54 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 55 | -v:: | 
|  | 56 | --invert-match:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 57 | Select non-matching lines. | 
|  | 58 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 59 | -h:: | 
|  | 60 | -H:: | 
| Junio C Hamano | 97efb00 | 2006-09-16 18:16:04 | [diff] [blame] | 61 | By default, the command shows the filename for each | 
|  | 62 | match. `-h` option is used to suppress this output. | 
|  | 63 | `-H` is there for completeness and does not do anything | 
|  | 64 | except it overrides `-h` given earlier on the command | 
|  | 65 | line. | 
|  | 66 |  | 
| Junio C Hamano | 85e45fa | 2006-08-13 07:47:41 | [diff] [blame] | 67 | --full-name:: | 
|  | 68 | When run from a subdirectory, the command usually | 
|  | 69 | outputs paths relative to the current directory. This | 
|  | 70 | option forces paths to be output relative to the project | 
|  | 71 | top directory. | 
|  | 72 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 73 | -E:: | 
|  | 74 | --extended-regexp:: | 
|  | 75 | -G:: | 
|  | 76 | --basic-regexp:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 77 | Use POSIX extended/basic regexp for patterns. Default | 
|  | 78 | is to use basic regexp. | 
|  | 79 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 80 | -F:: | 
|  | 81 | --fixed-strings:: | 
| Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 82 | Use fixed strings for patterns (don't interpret pattern | 
|  | 83 | as a regex). | 
|  | 84 |  | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 85 | -n:: | 
|  | 86 | Prefix the line number to matching lines. | 
|  | 87 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 88 | -l:: | 
|  | 89 | --files-with-matches:: | 
|  | 90 | --name-only:: | 
|  | 91 | -L:: | 
|  | 92 | --files-without-match:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 93 | Instead of showing every matched line, show only the | 
|  | 94 | names of files that contain (or do not contain) matches. | 
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 95 | For better compatibility with 'git-diff', --name-only is a | 
| Junio C Hamano | 074766f | 2008-02-22 22:57:06 | [diff] [blame] | 96 | synonym for --files-with-matches. | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 97 |  | 
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame^] | 98 | -z:: | 
|  | 99 | --null:: | 
|  | 100 | Output \0 instead of the character that normally follows a | 
|  | 101 | file name. | 
|  | 102 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 103 | -c:: | 
|  | 104 | --count:: | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 105 | Instead of showing every matched line, show the number of | 
|  | 106 | lines that match. | 
|  | 107 |  | 
|  | 108 | -[ABC] <context>:: | 
|  | 109 | Show `context` trailing (`A` -- after), or leading (`B` | 
|  | 110 | -- before), or both (`C` -- context) lines, and place a | 
| Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 111 | line containing `--` between contiguous groups of | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 112 | matches. | 
|  | 113 |  | 
| Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 114 | -<num>:: | 
|  | 115 | A shortcut for specifying -C<num>. | 
|  | 116 |  | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 117 | -f <file>:: | 
|  | 118 | Read patterns from <file>, one per line. | 
|  | 119 |  | 
| Junio C Hamano | 3901ffb | 2006-06-26 23:46:53 | [diff] [blame] | 120 | -e:: | 
|  | 121 | The next parameter is the pattern. This option has to be | 
|  | 122 | used for patterns starting with - and should be used in | 
| Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 123 | scripts passing user input to grep. Multiple patterns are | 
|  | 124 | combined by 'or'. | 
|  | 125 |  | 
| Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 126 | --and:: | 
|  | 127 | --or:: | 
|  | 128 | --not:: | 
|  | 129 | ( ... ):: | 
| Junio C Hamano | f9771f6 | 2007-01-17 17:42:30 | [diff] [blame] | 130 | Specify how multiple patterns are combined using Boolean | 
| Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 131 | expressions. `--or` is the default operator. `--and` has | 
|  | 132 | higher precedence than `--or`. `-e` has to be used for all | 
|  | 133 | patterns. | 
| Junio C Hamano | 3901ffb | 2006-06-26 23:46:53 | [diff] [blame] | 134 |  | 
| Junio C Hamano | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 135 | --all-match:: | 
|  | 136 | When giving multiple pattern expressions combined with `--or`, | 
|  | 137 | this flag is specified to limit the match to files that | 
|  | 138 | have lines to match all of them. | 
|  | 139 |  | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 140 | `<tree>...`:: | 
|  | 141 | Search blobs in the trees for specified patterns. | 
|  | 142 |  | 
| Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 143 | \--:: | 
| Junio C Hamano | a6331a8 | 2006-01-22 07:50:33 | [diff] [blame] | 144 | Signals the end of options; the rest of the parameters | 
|  | 145 | are <path> limiters. | 
|  | 146 |  | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 147 |  | 
| Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 148 | Example | 
|  | 149 | ------- | 
|  | 150 |  | 
|  | 151 | git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \):: | 
|  | 152 | Looks for a line that has `#define` and either `MAX_PATH` or | 
|  | 153 | `PATH_MAX`. | 
|  | 154 |  | 
| Junio C Hamano | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 155 | git grep --all-match -e NODE -e Unexpected:: | 
|  | 156 | Looks for a line that has `NODE` or `Unexpected` in | 
|  | 157 | files that have lines that match both. | 
|  | 158 |  | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 159 | Author | 
|  | 160 | ------ | 
| Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 161 | Originally written by Linus Torvalds <torvalds@osdl.org>, later | 
|  | 162 | revamped by Junio C Hamano. | 
|  | 163 |  | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 164 |  | 
|  | 165 | Documentation | 
|  | 166 | -------------- | 
|  | 167 | Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. | 
|  | 168 |  | 
|  | 169 | GIT | 
|  | 170 | --- | 
| Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 171 | Part of the linkgit:git[1] suite |