Git grep/search a specific branch

To grep another branch use:

git grep <regex> <branch-name>

To look at multiple commits, starting at some branch tip and working backwards: git grep can look in any particular tree (hence any particular commit since any given commit identifies a particular tree), but to iterate over every commit contained within some branch, you will need to do your own git rev-list:

git rev-list branch | while read rev; do git grep <regexp> $rev; done

for instance (but you may want to fancy this up more so that your grep stops once you've found what you are looking for).

If you want to look once, at the commit that is the tip of branch <branch>, and find (or fail to find) any instances of <regexp>, just do a simple:

git grep <regexp> branch

The loop form is only for the case where you want to start at that tip commit and keep working backwards through previous commits on the branch as well.

Tags:

Git