John Gietzen
John Gietzen

Reputation: 49565

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

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.

Upvotes: 6

Views: 3978

Answers (3)

Adam Dymitruk
Adam Dymitruk

Reputation: 129782

Use pick axe to see where in history the text was added or removed

git log --all -S'your text'

Upvotes: 1

Greg Hewgill
Greg Hewgill

Reputation: 994817

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

git grep foobar HEAD

Upvotes: 6

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143299

Something like that?

git grep -e textstring HEAD

or

git ls-files|xargs -I% -n 1 git cat-file -p HEAD:%|grep textstring

Upvotes: 4

Related Questions