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] |
| 12 | 'git-grep' [--cached] |
| 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 | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 18 | [-c | --count] [--all-match] |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 19 | [-A <post-context>] [-B <pre-context>] [-C <context>] |
Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 20 | [-f <file>] [-e] <pattern> |
| 21 | [--and|--or|--not|(|)|-e <pattern>...] [<tree>...] |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 22 | [--] [<path>...] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 23 | |
| 24 | DESCRIPTION |
| 25 | ----------- |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 26 | Look for specified patterns in the working tree files, blobs |
| 27 | registered in the index file, or given tree objects. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 28 | |
| 29 | |
| 30 | OPTIONS |
| 31 | ------- |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 32 | --cached:: |
| 33 | Instead of searching in the working tree files, check |
Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 34 | the blobs registered in the index file. |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 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 | |
Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 43 | -I:: |
| 44 | Don't match the pattern in binary files. |
| 45 | |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 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 | |
Junio C Hamano | 97efb00 | 2006-09-16 18:16:04 | [diff] [blame] | 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 | |
Junio C Hamano | 85e45fa | 2006-08-13 07:47:41 | [diff] [blame] | 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 | |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 67 | -E | --extended-regexp | -G | --basic-regexp:: |
| 68 | Use POSIX extended/basic regexp for patterns. Default |
| 69 | is to use basic regexp. |
| 70 | |
Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 71 | -F | --fixed-strings:: |
| 72 | Use fixed strings for patterns (don't interpret pattern |
| 73 | as a regex). |
| 74 | |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 75 | -n:: |
| 76 | Prefix the line number to matching lines. |
| 77 | |
Junio C Hamano | 074766f | 2008-02-22 22:57:06 | [diff] [blame^] | 78 | -l | --files-with-matches | --name-only | -L | --files-without-match:: |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 79 | Instead of showing every matched line, show only the |
| 80 | names of files that contain (or do not contain) matches. |
Junio C Hamano | 074766f | 2008-02-22 22:57:06 | [diff] [blame^] | 81 | For better compatability with git-diff, --name-only is a |
| 82 | synonym for --files-with-matches. |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 83 | |
| 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 |
Junio C Hamano | 341071d | 2006-06-04 07:24:48 | [diff] [blame] | 91 | line containing `--` between contiguous groups of |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 92 | matches. |
| 93 | |
Junio C Hamano | 9882a52 | 2007-04-27 08:22:22 | [diff] [blame] | 94 | -<num>:: |
| 95 | A shortcut for specifying -C<num>. |
| 96 | |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 97 | -f <file>:: |
| 98 | Read patterns from <file>, one per line. |
| 99 | |
Junio C Hamano | 3901ffb | 2006-06-26 23:46:53 | [diff] [blame] | 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 |
Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 103 | scripts passing user input to grep. Multiple patterns are |
| 104 | combined by 'or'. |
| 105 | |
| 106 | --and | --or | --not | ( | ):: |
Junio C Hamano | f9771f6 | 2007-01-17 17:42:30 | [diff] [blame] | 107 | Specify how multiple patterns are combined using Boolean |
Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 108 | expressions. `--or` is the default operator. `--and` has |
| 109 | higher precedence than `--or`. `-e` has to be used for all |
| 110 | patterns. |
Junio C Hamano | 3901ffb | 2006-06-26 23:46:53 | [diff] [blame] | 111 | |
Junio C Hamano | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 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 | |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 117 | `<tree>...`:: |
| 118 | Search blobs in the trees for specified patterns. |
| 119 | |
Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 120 | \--:: |
Junio C Hamano | a6331a8 | 2006-01-22 07:50:33 | [diff] [blame] | 121 | Signals the end of options; the rest of the parameters |
| 122 | are <path> limiters. |
| 123 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 124 | |
Junio C Hamano | 0044202 | 2006-08-03 00:29:36 | [diff] [blame] | 125 | Example |
| 126 | ------- |
| 127 | |
| 128 | git 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 | |
Junio C Hamano | fbe0052 | 2006-10-19 05:58:48 | [diff] [blame] | 132 | git 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 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 136 | Author |
| 137 | ------ |
Junio C Hamano | 617fdb8 | 2006-05-16 02:14:21 | [diff] [blame] | 138 | Originally written by Linus Torvalds <torvalds@osdl.org>, later |
| 139 | revamped by Junio C Hamano. |
| 140 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 141 | |
| 142 | Documentation |
| 143 | -------------- |
| 144 | Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. |
| 145 | |
| 146 | GIT |
| 147 | --- |
Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 148 | Part of the linkgit:git[7] suite |