gitblamevim-fugitivegit-blamegit-grep

git blame of particular lines inside all files filtered with grep command


I know how to run gblame inside a file.

I know how to grep a content inside all files in a directory.

I'd like to see gblame of particular lines around that one that contains a content. Example:

$ blame -R "content" ./

I see a list of files. I want to gblame all of theme, and understand who has touched those lines of code.


Solution

  • You can do it with Perl:

    git grep -n 'content' | perl -F':' -anpe '$_=`git blame -L$F[1],+1 $F[0]`'
    

    and if you want to create a custom command you can add something like this to your gitconfig in the alias section:

    gb = "!f() { git grep -n $1 | perl -F':' -anpe '$_=`git blame -L$F[1],+1 $F[0]`'; }; f"