git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] grep --no-index: allow use of "git grep" outside a git repository

From
Jeff King <peff@peff.net>
Date
Jan 16, 2010, 01:15 UTC
Message-ID
<20100116011512.GA27082@coredump.intra.peff.net>
In-Reply-To
<7vwrzin9jt.fsf@alter.siamese.dyndns.org>
On Fri, Jan 15, 2010 at 05:05:42PM -0800, Junio C Hamano wrote:
Show 10 quoted lines
> > Out of curiosity, what are the interesting features in git grep versus
> > other greps?
> 
> Three examples:
> 
>     git grep -e Junio --and -e Dscho --and -e Peff
> 
> is different from
> 
>     grep "Junio.*Dscho.*Peff"
Right. I would do:
  grep Junio | grep Dscho | grep Peff
No, it's not quite as accurate, as you are grepping the filenames too.

And no, it's not as efficient, but given that the first grep eliminates most of your input anyway, it's generally not a big deal.

So the short answer to my question seems to be "git grep has logical operators". I don't find that compelling, but I guess some people do. Thanks for satisfying my curiosity.

> I don't know how you would do these with "grep":
> 
>     git grep -e Junio --and -e Dscho --and --not -e Linus
I would do "grep Junio | grep Dscho | grep -v Linus".
>     git grep --all-match -e Junio -e Dscho

That one is a little harder (though it is not something I do very often, and I had to actually read the docs to find what --all-match does):

  grep Junio `grep -l Dscho *`
which of course has problems with exotic filenames.
-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 20 in “Filenames and prefixes in extended diffs”
  1. Andreas GruenbacherJan 13, 2010
  2. Junio C HamanoJan 13, 2010
  3. Junio C HamanoJan 14, 2010
  4. Nanako ShiraishiJan 15, 2010
  5. Junio C HamanoJan 15, 2010
  6. grep: prepare to run outside of a work treeJunio C Hamano, Jan 15, 2010
  7. grep --no-index: allow use of "git grep" outside a git repositoryJunio C Hamano, Jan 15, 2010
  8. Jeff KingJan 15, 2010
  9. Junio C HamanoJan 16, 2010
  10. Jeff KingJan 16, 2010
  11. Junio C HamanoJan 16, 2010
  12. David AguilarJan 16, 2010
  13. Junio C HamanoJan 16, 2010
  14. Jeff KingJan 18, 2010
  15. Junio C HamanoJan 18, 2010
  16. Junio C HamanoJan 18, 2010
  17. Jeff KingJan 18, 2010
  18. Junio C HamanoJan 18, 2010
  19. Jeff KingJan 18, 2010
  20. Andreas GruenbacherJan 18, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.