threads / discuss / 41940

Can `git grep` have `--Author` option?

Subject: Can `git grep` have `--Author` option?

## tl;dr

3 messages between Apr 5, 2016 and Apr 6, 2016.

replies: 2people: 3as markdown or json

Chen Bin· Apr 5, 2016, 23:45 UTC · lore
This is a feature request.
>From time to time, I want to re-use MY code. So git grep with --Author options is really useful. My current git version is 2.6.3, looks it doesn't have this option.
-- 
Best Regards,
Chen Bin

--
Help me, help you
Matthieu Moy· Apr 6, 2016, 06:05 UTC · re: Chen Bin · lore

Re: Can `git grep` have `--Author` option?

Chen Bin <chenbin.sh@gmail.com> writes:
Show 5 quoted lines
> This is a feature request.
>
> From time to time, I want to re-use MY code. So git grep with --Author
> options is really useful. My current git version is 2.6.3, looks it
> doesn't have this option.

Git doesn't "know" which line of code is yours. What it can do is walk through history to find out: this is "git blame", and you can already do "git blame | grep ...".

A "git grep --author" would need to blame all files before searching inside them, or grep first and blame each line in the result to filter out lines from the wrong author. That would be possible, but relatively hard to implement and painfully slow. Which probably explains why no one implemented it yet ...

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Junio C Hamano· Apr 6, 2016, 15:22 UTC · re: Matthieu Moy · lore

Re: Can `git grep` have `--Author` option?

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
Show 5 quoted lines
> A "git grep --author" would need to blame all files before searching
> inside them, or grep first and blame each line in the result to filter
> out lines from the wrong author. That would be possible, but relatively
> hard to implement and painfully slow. Which probably explains why no one
> implemented it yet ...

More importntly, it would not be all that useful in practice. I can see "git log -p --author=me" might, but people usually go from what the code does and then figure out who wrote it, e.g. you try to see if there is already code that does something similar to what you want to do in the current codebase, and then run blame on the found block to see what commit brought it in if you want to avoid borrowing code from questionable parties, not the other way around.

One possible use case would be when you asked to produce a code sample for interviewing or something, but then "log --author=$me" may be a more effective way to find one. It would allow you to demonstrate not just the quality of code but also your ability to clearly explain your idea to others.

← back to recent threads