Search Git remote all branches for file contents

后端 未结 2 1132
無奈伤痛
無奈伤痛 2020-12-24 07:50

Is it possible to search all of my Git remote branches for specific file contents (not just a file, but contents within them)?

My remotes are on GitHub, in case that

相关标签:
2条回答
  • 2020-12-24 08:29

    You can try this:

    git grep 'search-string' $(git ls-remote . 'refs/remotes/*' | cut -f 2)
    

    That will search all remote branches for search-string. Since the symbolic reference HEAD is mirrored, you may end up searching the same commit twice. Hopefully that's not an issue. If so, you can filter it out with:

    git grep 'search-string' \
        $(git ls-remote . 'refs/remotes/*' | grep -v HEAD | cut -f 2)
    

    If you need to dig through your entire history, you can also try:

    git grep 'search-string' $(git rev-list --all)
    
    0 讨论(0)
  • 2020-12-24 08:32

    Assuming you are tracking all remote branches, this will search it in all commits:

    git log --all -p | grep 'search-string'
    

    To track all remote branches:

    for remote in `git branch -r`; do git branch --track $remote; done
    
    0 讨论(0)
提交回复
热议问题