jdeuce jdeuce - 8 months ago 85
Git Question

grep for stuff in multiple git repositories

So I've inherited a fairly large code base from some other developers, with code stored in various git repositories.

Sometimes, it's hard to know which project a particular piece of code might lie in, or if that piece of code even exists in git.

What I want to be able to do is grep ALL the projects for some particular piece of text.

I'm using gitosis, so all the git repositories are stored in /home/git/repositories with a structure like:

|- project1
|- branches
|- config
|- description
|- hooks
|- info
|- objects
|- refs
|- project2
|- ...

I've tried doing a recursive grep for stuff in the objects directories like this:

grep -Hr "text" /home/git/repositories/*/objects

This fails to work as I intend of course, because the objects are stored in git's custom format.

What do?


Use git grep with a ref or --no-index:

cd /home/git/repositories
for i in *; do ( cd $i; git grep text HEAD ); done