24

How would I in git determine all lines still in existence that were from a specific author. Say for example, a Tony had worked on my project and I wanted to find all lines in my develop branch that still exists and were from a commit that Tony authored?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
stevebot
  • 23,275
  • 29
  • 119
  • 181
  • What does what you want differ from what `git blame` provides? – wnoise Aug 31 '15 at 22:38
  • 2
    @wnoise I am looking for a way to essentially search git blame for all files and just grep only the output for a specific author. – stevebot Aug 31 '15 at 22:40

2 Answers2

29

Maybe just git blame FILE | grep "Some Name".

Or if you want to recursively blame+search through multiple files:

for file in $(git ls-files); do git blame $file | grep "Some Name"; done

Note: I had originally suggested using the approach below, but the problem you can run into with it is that it may also possibly find files in your working directory that aren’t actually tracked by git, and so the git blame will fail for those files and break the loop.

find . -type f -name "*.foo" | xargs git blame | grep "Some Name"
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
15

sideshowbarker is mostly correct, but a fixed second command is:

find . -type f -exec git blame {} \; | grep "Some Name"

Though I would prefer to do:

for FILE in $(git ls-files) ; do git blame $FILE | grep "Some Name" ; done | less
Jesusaur
  • 594
  • 3
  • 22