Search Git remote all branches for file contents

后端 未结 2 1206
無奈伤痛
無奈伤痛 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)
    

提交回复
热议问题