Search code examples
gitgrepgit-blame

How can I search for a string that someone changed with git?


I would like to search for a specific string using git grep but I would like to filter the results by using git blame to know that the string I'm looking for was changed by a specific person.

I just don't know how can I combine them to get the results I want.

Thank you for your help.


Solution

  • You can write a little shell script to accomplish this:

    git rev-list --author=Doe HEAD |
    while read rev; do
        if git show -p $rev | grep "PATTERN" >/dev/null; then
            echo $rev
        fi
    done
    

    This will output the SHA's that are reachable by HEAD that have an author of "Doe" and have "PATTERN" in the commit content's.