3

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?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Alexander Mills
  • 78,517
  • 109
  • 412
  • 724

2 Answers2

2

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.

jthill
  • 48,781
  • 4
  • 72
  • 120
1

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

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Jonathan.Brink
  • 21,521
  • 16
  • 66
  • 107
  • Also see http://stackoverflow.com/questions/15292391/is-it-possible-to-perform-a-grep-search-in-all-the-branches-of-git-project – Jonathan.Brink Sep 11 '15 at 22:48