Re: Making git grep ignore binary the default
- From
El_Hoy <eloyesp@gmail.com>
- Date
- Oct 20, 2025, 17:20 UTC
- Message-ID
- <CAPapNH2UeRoKF9Tm5my59MXCxUQqEp+=4wzod8kYus_FQALwjQ@mail.gmail.com>
- In-Reply-To
- <0ef23314ca63d03467a50a93d2db1db3ad950ede.camel@virtuell-zuhause.de>
Ok, so if I understand correctly:
1. changing the default grep behaviour is not acceptable because it might break existing scripts. 2. Adding a config option might break a shared script on specific computers but that seems more reasonable. 3. There may be better ways to implement the setting that allow more flexibility.
Regarding point 1, I thought about this as a possible idea for a distant future with proper warnings, because I think this is a better default, but if the cost of making such a change is too big, we can omit this. If someone wants to come back to this, it might make sense to "grep" public code and check how much code would be affected to have more clarity about the costs.
On point 2, as Thomas points, there are many factors that might break a script that rely on 'git grep' directly for a dangerous task, this makes me think that we could add a `--porcelain` option to `git grep` to be used on scripts and be reliable, and it might ignore the config.
On point 3, the configuration could be made with more flexibility in mind, making it possible to ignore different files that are not binary (for example linguist-generated files). The downside of that approach is that it requires more configuration, while a single boolean for skipping binaries might be simpler. I'm ok with any approach.
That said, it seems important to add a flag to negate that setting for a single run, so if I have the setting to skip from grep some files, there should be a way to run grep on all the files, ignoring this setting, as it is also needed from time to time.
Regards.
--- Eloy
On Mon, Oct 20, 2025 at 12:24 PM Thomas Braun <thomas.braun@virtuell-zuhause.de> wrote:
Show 74 quoted lines
> > Am Samstag, dem 18.10.2025 um 00:52 +0000 schrieb brian m. carlson: > > On 2025-10-17 at 23:29:22, Thomas Braun wrote: > > > Am 17.10.2025 um 23:29 schrieb Junio C Hamano: > > > > 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. > > > > > > And if we only would have the config option "grep.ignoreBinary" > > > defaulting > > > to false with no default change whatsoever? I always want to ignore > > > binaries > > > when grepping and find it a bit tedious that I have to spell it out > > > all over > > > again. And yes I do have an alias as well but usually don't > > > remember to use > > > it. > > > > As Junio said, this could break existing scripts. If I write a > > command which uses `git grep` and expects to find all matching files, > > it would not work on your system with `grep.ignoreBinary` set to > > true. > > > > For instance, if I am working on a project for a company and must > > exclude source code with a certain vendor's copyright (because we > > don't have permission to distribute their code), then it would be > > very bad if I accidentally distributed that company's binary files > > due to `git grep -l PATTERN | xargs rm -f` not matching them since it > > would violate the license. > > > > This is just an example, but there are lots of cases where people do > > really want to search every file. > > I understand your use case. But if you don't control the environment > (git config settings among others) your task of finding things reliably > will just very easily break. > > Also in your use case, I either opted in to ignoring binary files, so I > should be wary of scripts assuming binary files are searched or I did > not and then nothing changes. > > > > I'm also curious what people are looking for in binary files with > > > git grep. > > > > It's common to mark PDFs or PostScript files as binary because they > > often contain embedded binary fonts, but they are actually mostly > > text > > and can be usefully searched with grep. For instance, I once created > > some awards for a non-profit based on combining standalone text-based > > PostScript code along with output from groff, so those independent > > pieces could end up being source that you might store in Git and > > search, > > even if many configurations would use `*.ps -text` in a system > > gitattributes file. > > > > Sometimes you also have images or such for a website, which contain > > XMP metadata (a form of XML-serialized RDF). Finding those images > > which have certain author metadata or a certain license URL embedded > > in them could be valuable. > > Thanks for the examples. > > The previous discussion dug up by Junio and Peff was an interesting > read. But from my understanding adding a git attribute like grep, which > allows to ignore "uninteresting" files for grep, does not solve your > backward compatibility concerns. Changing that looks easier now to be > done in 2012 comared to 2025 ;)