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