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

Re: Making git grep ignore binary the default

From
Jeff King <peff@peff.net>
Date
Oct 18, 2025, 10:22 UTC
Message-ID
<20251018102209.GH1060824@coredump.intra.peff.net>
In-Reply-To
<xmqqsefhxlmd.fsf@gitster.g>
On Fri, Oct 17, 2025 at 02:29:46PM -0700, Junio C Hamano wrote:
Show 6 quoted lines
> Simply because we have never needed to do something similar to "-a"
> and "-I" that we added in early 2006 for the past nearly 20 years.
> Also because GNU does not have any such thing to force "-a" or "-I"
> as default.  The biggest reason is that it would be surprising if
> such a change does not break existing scripts that have been written
> by people over the years.

I do think there is one difference between git-grep and regular grep here: the input file selection.

In "grep", the default set of files to search is nothing, and you have to tell it which files to look at. So aside from overly broad globs, the problem solves itself when you just don't pass in the binary paths.

But in git-grep, the default set of files to search is everything in the repository! So it is very easy to noisy hits from uninteresting files.

I think binary-ness of the files is a red herring, though. There are plenty of text files that are not interesting to grep either. I almost never want to see hits from po/ in git.git, for example. I get by with "^po/", or even "'*.c'" (extra single-quotes so that Git expands the glob). But I'd be happy if I could set a configuration knob to say that files with attribute X should be omitted from grep results (whether binary, or some custom attribute that I assign in .git/info/attributes).

I think we've discussed this before, and digging in the archive found this thread from 2012:

  https://lore.kernel.org/git/4f1d2a8b.a2d8320a.50ec.576d@mx.google.com/
I think some of those ideas came to fruition. You can do:
  git grep ':(attr:!binary)'

now (which obviously is harder than "-I", but the point is that it extends to any attribute if you want). But I still think it would be nice if there was a way to make it the default (without using an alias).

-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 9 of 10 in “Making git grep ignore binary the default”
  1. El_HoyOct 17, 2025
  2. Junio C HamanoOct 17, 2025
  3. Thomas BraunOct 17, 2025
  4. brian m. carlsonOct 18, 2025
  5. rsbecker@nexbridge.comOct 18, 2025
  6. Thomas BraunOct 20, 2025
  7. El_HoyOct 20, 2025
  8. Jeff KingOct 21, 2025
  9. Jeff KingOct 18, 2025
  10. Junio C HamanoOct 18, 2025

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.