Is it possible to perform a 'grep search' in all the branches of a Git project?

后端 未结 6 2061
深忆病人
深忆病人 2020-12-02 04:54

Is it possible to run git grep inside all the branches of a Git control sourced project? Or is there another command to run?

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 05:40

    I found this most useful:

    git grep -i foo `git for-each-ref --format='%(refname)' refs/`
    

    You'd need to adjust the last arguments depending on whether you want to only look at remote vs. local branches, i.e.:

    • git grep -i foo $(git for-each-ref --format='%(refname)' refs/remotes)
    • git grep -i foo $(git for-each-ref --format='%(refname)' refs/heads)

    The alias I created looks like this:

    grep-refs = !sh -c 'git grep "$0" "$@" "$(git for-each-ref --format=\"%(refname)\"" refs/)'
    

提交回复
热议问题