# How to restrict command “git grep” to the first search result per file?

5 messages from 2025-07-06 to 2025-07-08. Participants: Markus Elfring, Andreas Schwab, Phillip Wood.
Thread: https://gitlist.dev/t/63748

## Markus Elfring, 2025-07-06 11:28

Subject: How to restrict command “git grep” to the first search result per file?
Message-ID: <fb74577d-f7b8-4fde-ab5a-5283e70b8258@web.de>
URL: https://gitlist.dev/e/fb74577d-f7b8-4fde-ab5a-5283e70b8258%40web.de

```
Hello,

File contents can be searched also by the means of the program call “git grep”.
Would you become interested to find specified items only once in each file
(instead of multiple times)?

Regards,
Markus

```

## Andreas Schwab, 2025-07-06 11:42

Subject: Re: How to restrict command “git grep” to the first search result per file?
Message-ID: <87wm8lo89w.fsf@igel.home>
URL: https://gitlist.dev/e/87wm8lo89w.fsf%40igel.home
In-Reply-To: <fb74577d-f7b8-4fde-ab5a-5283e70b8258@web.de>

```
On Jul 06 2025, Markus Elfring wrote:

> File contents can be searched also by the means of the program call “git grep”.
> Would you become interested to find specified items only once in each file
> (instead of multiple times)?

Does "git grep -l" suit your needs?

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

```

## Markus Elfring, 2025-07-06 12:20

Subject: Re: How to restrict command “git grep” to the first search result per file?
Message-ID: <b1753222-0043-4b1d-acd4-9afac0197c65@web.de>
URL: https://gitlist.dev/e/b1753222-0043-4b1d-acd4-9afac0197c65%40web.de
In-Reply-To: <87wm8lo89w.fsf@igel.home>

```
>> Would you become interested to find specified items only once in each file
>> (instead of multiple times)?
> 
> Does "git grep -l" suit your needs?
I imagine that it can occasionally matter see a bit more context for a search result
besides a file name.

Regards,
Markus

```

## Phillip Wood, 2025-07-06 13:27

Subject: Re: How to restrict command “git grep” to the first search result per file?
Message-ID: <83b8fd7c-622a-4041-a825-89fe743b6c97@gmail.com>
URL: https://gitlist.dev/e/83b8fd7c-622a-4041-a825-89fe743b6c97%40gmail.com
In-Reply-To: <fb74577d-f7b8-4fde-ab5a-5283e70b8258@web.de>

```
Hi Markus

On 06/07/2025 12:28, Markus Elfring wrote:
> File contents can be searched also by the means of the program call “git grep”.
> Would you become interested to find specified items only once in each file
> (instead of multiple times)?

Looking at the man page for git grep there is a --max-count option which 
will limit the number of matches per file.

Thanks

Phillip

```

## Markus Elfring, 2025-07-08 05:30

Subject: Re: How to restrict command “git grep” to the first search result per file?
Message-ID: <a4b7226e-8069-485e-85c1-432047b847e3@web.de>
URL: https://gitlist.dev/e/a4b7226e-8069-485e-85c1-432047b847e3%40web.de
In-Reply-To: <87wm8lo89w.fsf@igel.home>

```
> Does "git grep -l" suit your needs?

Is it possible to determine such information also by a corresponding function
(instead of the mentioned program call interface)?

Would you occasionally like to transfer file details for search results
by other application programming interfaces?

Regards,
Markus

```
