本文介绍了是否有可能在git项目的所有分支中执行'grep搜索'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在git控件源项目的所有分支中运行git grep?还是有另一个命令来运行?

解决方案

问题:



  git rev-list --all | (while read rev; do git grep -e< regexp> $ rev; done)

这个答案的最后一部分的替代方案如下)



不要忘记这些设置,如果你想要的话:

 #允许扩展正则表达式
git config --global grep.extendRegexp true
#总是包含行号
git config --global grep .lineNumber true

这个别名也可以提供帮助:

  git config --global alias.ggrep --break --heading --line-number






注意: 是是过度杀伤。



  git branch -a | tr -d \ * | xargs git grep< regexp> 





  alias grep_all =git branch -a | tr -d \ * | xargs git grep
grep_all< regexp>

2016年8月更新:在评论中推荐



  git branch -a | tr -d \ * | sed'/  - > / d'| xargs git grep< regexp> 

即:

  alias grep_all =git branch -a | tr -d \ * | sed'/  - > / d'| xargs git grep
grep_all< regexp>


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

解决方案

The question "How to grep (search) committed code in the git history?" recommends:

 git grep <regexp> $(git rev-list --all)

That searches through all the commits, which should include all the branches.

Another form would be:

git rev-list --all | (
    while read revision; do
        git grep -F 'yourWord' $revision
    done
)

You can find even more example in this article:

git rev-list --all | (while read rev; do git grep -e <regexp> $rev; done)

(see an alternative in the last section of this answer, below)

Don't forget those settings, if you want them:

# Allow Extended Regular Expressions
git config --global grep.extendRegexp true
# Always Include Line Numbers
git config --global grep.lineNumber true

This alias can help too:

git config --global alias.g "grep --break --heading --line-number"


Note: chernjie suggested that git rev-list --all is an overkill.

git branch -a | tr -d \* | xargs git grep <regexp>
alias grep_all="git branch -a | tr -d \* | xargs git grep"
grep_all <regexp>

Update August 2016: R.M. recommends in the comments

 git branch -a | tr -d \* | sed '/->/d' | xargs git grep <regexp>

That is:

alias grep_all="git branch -a | tr -d \* | sed '/->/d' | xargs git grep"
grep_all <regexp>

这篇关于是否有可能在git项目的所有分支中执行'grep搜索'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:16