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

后端 未结 6 2060
深忆病人
深忆病人 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:29

    git log can be a more effective way of searching for text across all branches, especially if there are many matches, and you want to see more recent (relevant) changes first.

    git log -p --all -S 'search string'
    git log -p --all -G 'match regular expression'
    

    These log commands list commits that add or remove the given search string/regex, (generally) more recent first. The -p option causes the relevant diff to be shown where the pattern was added or removed, so you can see it in context.

    Having found a relevant commit that adds the text you were looking for (eg. 8beeff00d), find the branches that contain the commit:

    git branch -a --contains 8beeff00d
    

提交回复
热议问题