Git grep/search a specific branch

后端 未结 2 526
误落风尘
误落风尘 2021-01-04 07:57

I am looking for a way to grep a certain branch. Simple?

To show a specific file in a branch, one would use:

git show branch:my_branch bla_sheep.txt
         


        
相关标签:
2条回答
  • 2021-01-04 08:08

    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.

    0 讨论(0)
  • 2021-01-04 08:08

    To grep another branch use:

    git grep <regex> <branch-name>
    
    0 讨论(0)
提交回复
热议问题