-3

How can I search all of my Git remote branches for the commit where a specific line or two of code were added (not just a file, but contents within them)?

My repos are all on github.

Ben James
  • 121,135
  • 26
  • 193
  • 155
professormeowingtons
  • 3,504
  • 7
  • 36
  • 50

2 Answers2

3

Does git blame suit your needs? You can run it on a specific revision (irrelevant to whether it's on the remote or not, see How to 'git blame' on the remote-side repository?).

For example:

$ git blame master file_in_question.c
$ git blame 20f89e16 file_in_question.c

Also, if your repositories are on GitHub, you can use their interface to git blame if you'd prefer. See "Using git blame to trace changes in a file"

Community
  • 1
  • 1
David Cain
  • 16,484
  • 14
  • 65
  • 75
  • It might, but I need to check for specific contents of a file. How would I search through all commits, in all remote branches, looking for the point when a specific line of code was added? – professormeowingtons Aug 16 '13 at 19:08
  • 1
    That's precisely what `git blame` does (see [Using git blame to trace changes in a file](https://help.github.com/articles/using-git-blame-to-trace-changes-in-a-file)). Just run `git blame ` for each non-merged branch (with merged branches, just take the more recent, `git blame` will navigate the whole history). – David Cain Aug 16 '13 at 19:12
2

In addition to using git blame, you can also search in local branches with

git log -S<search-string> --source --all

It may search your local remote-tracking branches too, but I'm not sure. You could always just make a local branch of your remote ones, of course. See git: finding a commit that introduced a string for more details.

There's also a regex version that you could use (see git log docs):

-G<regex>

Look for differences whose added or removed line matches the given <regex>.

Community
  • 1
  • 1