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