Git grep / search for a specific branch

I am looking for a way to grep a specific branch. Plain?

To show a specific file in a branch, use:

git show branch:my_branch bla_sheep.txt

Similar syntax is used for diff, etc.

Is there a way to just grep branches:

git grep branch:my_branch <regex>
+8
source share
2 answers

Not really, no. git grepcan search in any specific tree (therefore, in any specific commit, since each specific commit identifies a specific tree), but to iterate over each commit contained in a branch, you will need to create your own git rev-list:

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

for example (but you may want to come up with this more so that your grep stops as soon as you find what you were looking for).

, <branch>, ( ) <regexp>, :

git grep <regexp> branch

, .

+6

grep :

git grep <regex> <branch-name>
+4

Source: https://habr.com/ru/post/1615493/


All Articles