threads / discuss / 63748

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

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

## tl;dr

5 messages between Jul 6, 2025 and Jul 8, 2025.

replies: 4people: 3as markdown or json

Markus Elfring· Jul 6, 2025, 11:28 UTC · lore
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· Jul 6, 2025, 11:42 UTC · re: Markus Elfring · lore

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

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· Jul 6, 2025, 12:20 UTC · re: Andreas Schwab · lore

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

>> 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

Markus Elfring· Jul 8, 2025, 05:30 UTC · re: Andreas Schwab · lore

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

> 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

Phillip Wood· Jul 6, 2025, 13:27 UTC · re: Markus Elfring · lore

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

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

← back to recent threads