Documentation / git-grep.txton commit gitweb: parse_commit_text encoding fix (5ed5bbc)
   1git-grep(1)
   2===========
   3
   4NAME
   5----
   6git-grep - Print lines matching a pattern
   7
   8
   9SYNOPSIS
  10--------
  11[verse]
  12'git grep' [--cached]
  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]
  20           [--color | --no-color]
  21           [-A <post-context>] [-B <pre-context>] [-C <context>]
  22           [-f <file>] [-e] <pattern>
  23           [--and|--or|--not|(|)|-e <pattern>...] [<tree>...]
  24           [--] [<path>...]
  25
  26DESCRIPTION
  27-----------
  28Look for specified patterns in the working tree files, blobs
  29registered in the index file, or given tree objects.
  30
  31
  32OPTIONS
  33-------
  34--cached::
  35        Instead of searching in the working tree files, check
  36        the blobs registered in the index file.
  37
  38-a::
  39--text::
  40        Process binary files as if they were text.
  41
  42-i::
  43--ignore-case::
  44        Ignore case differences between the patterns and the
  45        files.
  46
  47-I::
  48        Don't match the pattern in binary files.
  49
  50-w::
  51--word-regexp::
  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
  56-v::
  57--invert-match::
  58        Select non-matching lines.
  59
  60-h::
  61-H::
  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
  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
  74-E::
  75--extended-regexp::
  76-G::
  77--basic-regexp::
  78        Use POSIX extended/basic regexp for patterns.  Default
  79        is to use basic regexp.
  80
  81-F::
  82--fixed-strings::
  83        Use fixed strings for patterns (don't interpret pattern
  84        as a regex).
  85
  86-n::
  87        Prefix the line number to matching lines.
  88
  89-l::
  90--files-with-matches::
  91--name-only::
  92-L::
  93--files-without-match::
  94        Instead of showing every matched line, show only the
  95        names of files that contain (or do not contain) matches.
  96        For better compatibility with 'git-diff', --name-only is a
  97        synonym for --files-with-matches.
  98
  99-z::
 100--null::
 101        Output \0 instead of the character that normally follows a
 102        file name.
 103
 104-c::
 105--count::
 106        Instead of showing every matched line, show the number of
 107        lines that match.
 108
 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
 116-[ABC] <context>::
 117        Show `context` trailing (`A` -- after), or leading (`B`
 118        -- before), or both (`C` -- context) lines, and place a
 119        line containing `--` between contiguous groups of
 120        matches.
 121
 122-<num>::
 123        A shortcut for specifying -C<num>.
 124
 125-p::
 126--show-function::
 127        Show the preceding line that contains the function name of
 128        the match, unless the matching line is a function name itself.
 129        The name is determined in the same way as 'git diff' works out
 130        patch hunk headers (see 'Defining a custom hunk-header' in
 131        linkgit:gitattributes[5]).
 132
 133-f <file>::
 134        Read patterns from <file>, one per line.
 135
 136-e::
 137        The next parameter is the pattern. This option has to be
 138        used for patterns starting with - and should be used in
 139        scripts passing user input to grep.  Multiple patterns are
 140        combined by 'or'.
 141
 142--and::
 143--or::
 144--not::
 145( ... )::
 146        Specify how multiple patterns are combined using Boolean
 147        expressions.  `--or` is the default operator.  `--and` has
 148        higher precedence than `--or`.  `-e` has to be used for all
 149        patterns.
 150
 151--all-match::
 152        When giving multiple pattern expressions combined with `--or`,
 153        this flag is specified to limit the match to files that
 154        have lines to match all of them.
 155
 156`<tree>...`::
 157        Search blobs in the trees for specified patterns.
 158
 159\--::
 160        Signals the end of options; the rest of the parameters
 161        are <path> limiters.
 162
 163
 164Example
 165-------
 166
 167git grep -e \'#define\' --and \( -e MAX_PATH -e PATH_MAX \)::
 168        Looks for a line that has `#define` and either `MAX_PATH` or
 169        `PATH_MAX`.
 170
 171git grep --all-match -e NODE -e Unexpected::
 172        Looks for a line that has `NODE` or `Unexpected` in
 173        files that have lines that match both.
 174
 175Author
 176------
 177Originally written by Linus Torvalds <torvalds@osdl.org>, later
 178revamped by Junio C Hamano.
 179
 180
 181Documentation
 182--------------
 183Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
 184
 185GIT
 186---
 187Part of the linkgit:git[1] suite