2

I'd like to git grep in the usual way, but with something like the additional insight of git blame in the displayed results.

In some instances I probably would benefit from including the metadata in the search query (show only results written by Bob), and in others I'd rather just use my own human judgement. I guess I'm flexible with which way that goes.

sh1
  • 4,324
  • 17
  • 30
  • 3
    Grep can't show blame-like information because it does not peruse previous commits line by line the way blame does. So if you have some git-grep output that fingers some particular commit, *run `git blame` starting from that commit* as a separate command; you'll find what you need. Note that there are options to `git blame` to make it possible to use it from scripts, so you may be able build your own command that does what you want. – torek Dec 02 '22 at 21:17

1 Answers1

2

I added the following to my git aliases:

grame = "!r() { git grep -n $1 $2 | while IFS=: read i j k; do git blame -f -L $j,$j $i; done }; r"

Which I shamelessly stole and adapted from: https://gist.github.com/lonnen/3101795

It might need some more work.

Vser
  • 578
  • 4
  • 18