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