To find a version containing the regular expression foo in the history of any branch:
foo
git grep foo $(git rev-list --all)
You may also limit the search to a file extension, e.g. Ruby files (.rb) like this:
.rb
git grep foo $(git rev-list --all) -- *.rb