Re: [PATCH 2/2] builtin/grep.c: teach '-o', '--only-matching' to 'git-grep'
- From
Taylor Blau <me@ttaylorr.com>
- Date
- May 8, 2018, 00:27 UTC
- Message-ID
- <20180508002748.GB6763@syl.local>
- In-Reply-To
- <CAPig+cSRJWW4-7vj6wK8aOfNB20bqUCSOOySjdPci1r5Vb83Uw@mail.gmail.com>
On Sat, May 05, 2018 at 03:36:12AM -0400, Eric Sunshine wrote:
Show 16 quoted lines
> On Sat, May 5, 2018 at 12:03 AM, Taylor Blau <me@ttaylorr.com> wrote:
> > Teach GNU grep(1)'s '-o' ('--only-matching') to 'git-grep'. This option
> > prints only the matching components of each line. It writes multiple
> > lines if more than one match exists on a given line.
> >
> > For example:
> >
> > $ git grep -on --column --heading git -- README.md | head -3
> > README.md
> > 15:56:git
> > 18:20:git
> >
> > By using show_line_header(), 'git grep --only-matching' correctly
> > respects the '--header' option:
>
> What is the '--header' option? I don't see it used in any example.I think '--header' is a typo for '--heading', which is used in the following example.
Show 8 quoted lines
> > $ git grep -on --column --heading git -- README.md | head -4 > > README.md > > 15:56:git > > 18:20:git > > 19:16:git > > How does this example differ from the earlier example (other than > showing 4 lines of output rather than 3)?
Ack. I clipped from my terminal what I meant to be the seocnd example, and pasted it in for both examples. They are meant to be as follows:
1. 'git grep' without heading, showing the full line prefix, and 2. 'git grep' with heading, showing the file heading with '--heading'.
The later has '| head -n4' on the end to include 3+1 lines (3 matches, 1 heading) whereas the former has '| head -n3' to include 3 lines (3 matches, no heading).
I have updated my patch locally to reflect this.
Thanks, Taylor