Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 964
sensorario Avatar asked Feb 25 '15 16:02

sensorario


People also ask

How do I blame a file in git?

The git blame command is used to examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was. The output format of git blame can be altered with various command line options.

Which statement is the best comparison between git grep and grep?

The git grep version will only search in files tracked by git, whereas the grep version will search everything in the directory. So far so similar; either one could be better depending on what you want to achieve.

What is git grep?

`git grep` command is used to search in the checkout branch and local files. But if the user is searching the content in one branch, but the content is stored in another branch of the repository, then he/she will not get the searching output.

How do I git blame on GitHub?

For more information, see Git's git blame documentation. On GitHub.com, navigate to the main page of the repository. Click to open the file whose line history you want to view. In the upper-right corner of the file view, click Blame to open the blame view.


1 Answers

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"
like image 164
Cash Lo Avatar answered Sep 21 '22 02:09

Cash Lo