Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I search a bare Git repo for a string in the contents of the current revision?

Tags:

git

Is it possible for Git to search the contents of the text files in a bare repository for a specific string?

I'm building a search feature for WebGit .NET to allow for searching the current state of all repositories for text.

like image 309
John Gietzen Avatar asked Dec 28 '22 11:12

John Gietzen


2 Answers

It sounds like you're looking for git grep. When searching a bare repository, you must specify somewhere to search:

git grep foobar HEAD
like image 169
Greg Hewgill Avatar answered Feb 16 '23 04:02

Greg Hewgill


Something like that?

git grep -e textstring HEAD

or

git ls-files|xargs -I% -n 1 git cat-file -p HEAD:%|grep textstring
like image 42
Michael Krelin - hacker Avatar answered Feb 16 '23 04:02

Michael Krelin - hacker