Reputation: 24035
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?
Upvotes: 28
Views: 10161
Reputation: 33
As a compliment to @sideshowbarker 's answer, if you want to see the files to which the lines belong, you can type the following:
for file in $(git ls-files)
do
contents=$(git blame $file | grep "Some Name")
if [[ ! -z "$contents" ]]
then
echo "=== $file ==="
echo $contents
fi
done
Sorry if the coding style isn't appropriate. I don't code in shell script very often.
Upvotes: 0
Reputation: 88286
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"
Upvotes: 31
Reputation: 603
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
Upvotes: 16