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

Re: git-grep to operate across who repository and not just CWD?

From
Phil Hord <hordp@cisco.com>
Date
Feb 28, 2011, 22:25 UTC
Message-ID
<4D6C20F6.3070905@cisco.com>
In-Reply-To
<4D6B6A8B.20709@drmicha.warpmail.net>
(cc list: Pardon this duplicate attempt)
On 02/28/2011 04:27 AM, Michael J Gruber wrote:
Show 15 quoted lines
> David Chanters venit, vidit, dixit 28.02.2011 01:17:
>> > Hi all,
>> > 
>> > [ Please Cc me as I am not subscribed to this list, thanks. ]
>> > 
>> > I'm wondering if there's an easy way to get git-grep (and I suppose
>> > other commands which operate on a per-repository level rather than
>> > per-tree) to work across the whole repository?
> git grep -- $(git rev-parse --show-cdup)
>
> is the best we have right now. I think we're still looking for a good
> way to denote "root of repo" (like "." for cwd).
>
> Also, we're thinking of changing a few defaults (to repo-wide), but "git
> grep" is meant to stay close to ordinary grep.

But git grep is different than grep in exactly the "files selection" area. With grep, I always have to specify the files to search. With git-grep, I don't.

Oridinary grep with no paths fails (reads stdin), so when I make this mistake it is always immediately evident. I retry the command with paths/wildcards. But git-grep with no path "works" and I am likely to forget that it worked only on my $PWD.

git-grep also includes subdirectories and excludes untracked files by default. This makes git-grep feel like the "repository grep" tool that it is. The fact that it does _not_ search from the top of the repository by default seems (to me) to be the only oddball case.

I would be much more comfortable with David's proposed option turned on always. When I want to search "here", I can add a dot.

  git grep foo       # search the whole repository
  git grep foo -- .  # Search only from $PWD

Maybe it's dangerous as an always-on option, as it can break scripts. And I'd be happy-ish even with a --full-tree option. But I think I would eventually alias it so it always does what I expect.

I know that's not what the original question was, but it's the behavior I often erroneously expect.

Thoughts?
Phil
Previous: Junio C HamanoNext: Michael J Gruber
Message 6 of 46 in “git-grep to operate across who repository and not just CWD?”
  1. David ChantersFeb 28, 2011
  2. Michael J GruberFeb 28, 2011
  3. Jay SoffianFeb 28, 2011
  4. Junio C HamanoFeb 28, 2011
  5. Junio C HamanoFeb 28, 2011
  6. Phil HordFeb 28, 2011
  7. Michael J GruberMar 1, 2011
  8. Nguyen Thai Ngoc DuyMar 1, 2011
  9. Michael J GruberMar 1, 2011
  10. Nguyen Thai Ngoc DuyMar 1, 2011
  11. Nguyen Thai Ngoc DuyMar 1, 2011
  12. 0/2 grep --full-treeMichael J Gruber, Mar 1, 2011
  13. 1/2 grep: --full-treeMichael J Gruber, Mar 1, 2011
  14. 2/2 grep: make --full-tree work with pathspecsMichael J Gruber, Mar 1, 2011
  15. Junio C HamanoMar 1, 2011
  16. setup.c: denote repo wide pathspecs by ':'Michael J Gruber, Mar 1, 2011
  17. Nguyen Thai Ngoc DuyMar 1, 2011
  18. Michael J GruberMar 1, 2011
  19. Nguyen Thai Ngoc DuyMar 1, 2011
  20. Michael J GruberMar 1, 2011
  21. Nguyen Thai Ngoc DuyMar 1, 2011
  22. Junio C HamanoMar 1, 2011
  23. Michael J GruberMar 1, 2011
  24. Junio C HamanoMar 1, 2011
  25. Sverre RabbelierMar 2, 2011
  26. Nguyen Thai Ngoc DuyMar 2, 2011
  27. Michael J GruberMar 2, 2011
  28. Junio C HamanoMar 2, 2011
  29. Michael J GruberMar 2, 2011
  30. Miles BaderMar 3, 2011
  31. Junio C HamanoMar 3, 2011
  32. Phil HordMar 3, 2011
  33. Michael J GruberMar 3, 2011
  34. Phil HordMar 1, 2011
  35. James PickensMar 1, 2011
  36. Nguyen Thai Ngoc DuyMar 2, 2011
  37. Phil HordMar 3, 2011
  38. Michael J GruberMar 3, 2011
  39. Michael J GruberMar 1, 2011
  40. Phil HordMar 1, 2011
  41. pathspec: reserve some letters after a colon pathspecNguyễn Thái Ngọc Duy, Mar 23, 2011
  42. Junio C HamanoMar 23, 2011
  43. Michael J GruberMar 24, 2011
  44. Nguyen Thai Ngoc DuyMar 24, 2011
  45. Junio C HamanoMar 24, 2011
  46. Junio C HamanoMar 24, 2011

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.