<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<article lang="en" id="git-grep(1)">
<articleinfo>
    <title>git-grep(1)</title>
        <indexterm>
                <primary>git-grep(1)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>git-grep - Print lines matching a pattern</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git grep</emphasis> [--cached]
           [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
           [-v | --invert-match] [-h|-H] [--full-name]
           [-E | --extended-regexp] [-G | --basic-regexp]
           [-F | --fixed-strings] [-n]
           [-l | --files-with-matches] [-L | --files-without-match]
           [-z | --null]
           [-c | --count] [--all-match]
           [-A &lt;post-context&gt;] [-B &lt;pre-context&gt;] [-C &lt;context&gt;]
           [-f &lt;file&gt;] [-e] &lt;pattern&gt;
           [--and|--or|--not|(|)|-e &lt;pattern&gt;&#8230;] [&lt;tree&gt;&#8230;]
           [--] [&lt;path&gt;&#8230;]</literallayout>
</blockquote>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>Look for specified patterns in the working tree files, blobs
registered in the index file, or given tree objects.</simpara>
</simplesect>
<simplesect id="_options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
--cached
</term>
<listitem>
<simpara>
        Instead of searching in the working tree files, check
        the blobs registered in the index file.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-a
</term>
<term>
--text
</term>
<listitem>
<simpara>
        Process binary files as if they were text.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-i
</term>
<term>
--ignore-case
</term>
<listitem>
<simpara>
        Ignore case differences between the patterns and the
        files.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-I
</term>
<listitem>
<simpara>
        Don&#8217;t match the pattern in binary files.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-w
</term>
<term>
--word-regexp
</term>
<listitem>
<simpara>
        Match the pattern only at word boundary (either begin at the
        beginning of a line, or preceded by a non-word character; end at
        the end of a line or followed by a non-word character).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-v
</term>
<term>
--invert-match
</term>
<listitem>
<simpara>
        Select non-matching lines.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-h
</term>
<term>
-H
</term>
<listitem>
<simpara>
        By default, the command shows the filename for each
        match.  <literal>-h</literal> option is used to suppress this output.
        <literal>-H</literal> is there for completeness and does not do anything
        except it overrides <literal>-h</literal> given earlier on the command
        line.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--full-name
</term>
<listitem>
<simpara>
        When run from a subdirectory, the command usually
        outputs paths relative to the current directory.  This
        option forces paths to be output relative to the project
        top directory.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-E
</term>
<term>
--extended-regexp
</term>
<term>
-G
</term>
<term>
--basic-regexp
</term>
<listitem>
<simpara>
        Use POSIX extended/basic regexp for patterns.  Default
        is to use basic regexp.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-F
</term>
<term>
--fixed-strings
</term>
<listitem>
<simpara>
        Use fixed strings for patterns (don&#8217;t interpret pattern
        as a regex).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-n
</term>
<listitem>
<simpara>
        Prefix the line number to matching lines.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-l
</term>
<term>
--files-with-matches
</term>
<term>
--name-only
</term>
<term>
-L
</term>
<term>
--files-without-match
</term>
<listitem>
<simpara>
        Instead of showing every matched line, show only the
        names of files that contain (or do not contain) matches.
        For better compatibility with <emphasis>git-diff</emphasis>, --name-only is a
        synonym for --files-with-matches.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-z
</term>
<term>
--null
</term>
<listitem>
<simpara>
        Output \0 instead of the character that normally follows a
        file name.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-c
</term>
<term>
--count
</term>
<listitem>
<simpara>
        Instead of showing every matched line, show the number of
        lines that match.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-[ABC] &lt;context&gt;
</term>
<listitem>
<simpara>
        Show <literal>context</literal> trailing (<literal>A</literal>&#8201;&#8212;&#8201;after), or leading (<literal>B</literal>
       &#8201;&#8212;&#8201;before), or both (<literal>C</literal>&#8201;&#8212;&#8201;context) lines, and place a
        line containing <literal>--</literal> between contiguous groups of
        matches.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-&lt;num&gt;
</term>
<listitem>
<simpara>
        A shortcut for specifying -C&lt;num&gt;.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-f &lt;file&gt;
</term>
<listitem>
<simpara>
        Read patterns from &lt;file&gt;, one per line.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-e
</term>
<listitem>
<simpara>
        The next parameter is the pattern. This option has to be
        used for patterns starting with - and should be used in
        scripts passing user input to grep.  Multiple patterns are
        combined by <emphasis>or</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--and
</term>
<term>
--or
</term>
<term>
--not
</term>
<term>
( &#8230; )
</term>
<listitem>
<simpara>
        Specify how multiple patterns are combined using Boolean
        expressions.  <literal>--or</literal> is the default operator.  <literal>--and</literal> has
        higher precedence than <literal>--or</literal>.  <literal>-e</literal> has to be used for all
        patterns.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--all-match
</term>
<listitem>
<simpara>
        When giving multiple pattern expressions combined with <literal>--or</literal>,
        this flag is specified to limit the match to files that
        have lines to match all of them.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<literal>&lt;tree&gt;&#8230;</literal>
</term>
<listitem>
<simpara>
        Search blobs in the trees for specified patterns.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--
</term>
<listitem>
<simpara>
        Signals the end of options; the rest of the parameters
        are &lt;path&gt; limiters.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_example">
<title>Example</title>
<variablelist>
<varlistentry>
<term>
git grep -e '#define\' --and \( -e MAX_PATH -e PATH_MAX \)
</term>
<listitem>
<simpara>
        Looks for a line that has <literal>#define</literal> and either <literal>MAX_PATH</literal> or
        <literal>PATH_MAX</literal>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
git grep --all-match -e NODE -e Unexpected
</term>
<listitem>
<simpara>
        Looks for a line that has <literal>NODE</literal> or <literal>Unexpected</literal> in
        files that have lines that match both.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_author">
<title>Author</title>
<simpara>Originally written by Linus Torvalds &lt;<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>&gt;, later
revamped by Junio C Hamano.</simpara>
</simplesect>
<simplesect id="_documentation">
<title>Documentation</title>
<simpara>Documentation by Junio C Hamano and the git-list &lt;<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>&gt;.</simpara>
</simplesect>
<simplesect id="_git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
</simplesect>
</article>
