# Has anyone tried to implement git grep --blame?

2 messages from 2013-05-29 to 2013-05-30. Participants: Ævar Arnfjörð Bjarmason, Jakub Narebski.
Thread: https://gitlist.dev/t/33968

## Ævar Arnfjörð Bjarmason, 2013-05-29 05:41

Subject: Has anyone tried to implement git grep --blame?
Message-ID: <CACBZZX5R=zaNBv4OGh30dxj+BAi26jDxDBO5pZTQ2QxGUB6WXw@mail.gmail.com>
URL: https://gitlist.dev/e/CACBZZX5R%3DzaNBv4OGh30dxj%2BBAi26jDxDBO5pZTQ2QxGUB6WXw%40mail.gmail.com

```
This would be so much more convenient if git-grep supported it natively:

$ git grep -n 'if \(0\)' | perl -pe's/([^:]+):([^:]+).*/`git blame -L
$2,$2 $1`/se'
d18f76dc (Ævar Arnfjörð Bjarmason 2010-08-17 09:24:38 +0000 2278)   if (0)
65648283 (David Brown 2007-12-25 19:56:29 -0800 433) if (0) {

I.e. with all the coloring/pager interaction. Some Googling around
reveals people piping things to git-blame like that, but has anyone
made a stab at a smarter implementation (that would know to blame the
whole file if it had lots of hits etc..).

Don't know if I have time myself, but I'd be very pleased if someone
hacked that up.

```

## Jakub Narebski, 2013-05-30 10:12

Subject: Re: Has anyone tried to implement git grep --blame?
Message-ID: <loom.20130530T121036-210@post.gmane.org>
URL: https://gitlist.dev/e/loom.20130530T121036-210%40post.gmane.org
In-Reply-To: <CACBZZX5R=zaNBv4OGh30dxj+BAi26jDxDBO5pZTQ2QxGUB6WXw@mail.gmail.com>

```
Ævar Arnfjörð Bjarmason <avarab <at> gmail.com> writes:

> This would be so much more convenient if git-grep supported it natively:
> 
> $ git grep -n 'if \(0\)' | perl -pe's/([^:]+):([^:]+).*/`git blame -L
> $2,$2 $1`/se'
> d18f76dc (Ævar Arnfjörð Bjarmason 2010-08-17 09:24:38 +0000 2278)   if (0)
> 65648283 (David Brown 2007-12-25 19:56:29 -0800 433) if (0) {
> 
> I.e. with all the coloring/pager interaction. Some Googling around
> reveals people piping things to git-blame like that, but has anyone
> made a stab at a smarter implementation (that would know to blame the
> whole file if it had lots of hits etc..).
> 
> Don't know if I have time myself, but I'd be very pleased if someone
> hacked that up.

Errr... 'git blame -L' supports regexps as starting and ending point,
see git-blame(1) manpage:

    git blame -L '/^sub hello {/,/^}$/' foo

It does not color matching, though...
-- 
Jakub Narębski

```
