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,738
  • 21
  • 105
  • 131
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

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
  • 55,082
  • 5
  • 77
  • 137
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,738
  • 21
  • 105
  • 131
Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • 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