Alexander Mills
Alexander Mills

Reputation: 100000

Search all Git branches for a keyword

I swear I wrote a test called "heartbeatTest" or "heartbeatRouteTest" in one of the branches of a Git repository.

But I can't find it in any of the branches. Is there a way to do a global search with Git to find a matching phrase in any branch for a particular local/remote repository?

Upvotes: 3

Views: 1927

Answers (2)

Jonathan.Brink
Jonathan.Brink

Reputation: 25383

Check out Git grep

git grep heartbeat $(git rev-list --all)

You could be a little more specific with:

git grep heartbeat.*Test $(git rev-list --all)

Here is a nice article with more examples of using Git grep: Search a Git repository like a ninja

Upvotes: 1

jthill
jthill

Reputation: 60255

You want

git log -G"$regex" --all

or

git log -S"string" --all

git log reference

which search all current history for commits that change lines (-G) or change the number of lines (-S) containing a match. There are plenty of options to alter git log's selection of starting points to walk through history.

Upvotes: 2

Related Questions