I want to list every contributors for each file in the repository.
Here is currently what I do:
find . | xargs -L 1 git blame -f | cut -d' ' -f 2-4 | sort | uniq
This is very slow. Is there a better solution ?
Taking ДМИТРИЙ's answer as a base, I'd say the following :
git ls-tree -r --name-only master ./ | while read file ; do
echo "=== $file"
git log --follow --pretty=format:%an -- $file | sort | uniq
done
Enhancement is that it follows file's rename in its history, and behaves correctly if files contain spaces (| while read file
)
I would write a small script that analyzes the output of git log --stat --pretty=format:'%cN'
; something along the lines of:
#!/usr/bin/env perl
my %file;
my $contributor = q();
while (<>) {
chomp;
if (/^\S/) {
$contributor = $_;
}
elsif (/^\s*(.*?)\s*\|\s*\d+\s*[+-]+/) {
$file{$1}{$contributor} = 1;
}
}
for my $filename (sort keys %file) {
print "$filename:\n";
for my $contributor (sort keys %{$file{$filename}}) {
print " * $contributor\n";
}
}
(Written just quickly; does not cover cases like binary files.)
If you stored this script, e.g., as ~/git-contrib.pl
, you could call it with:
git log --stat=1000,1000 --pretty=format:'%cN' | perl ~/git-contrib.pl
Advantage: call git
only once, which implies that it is reasonably fast. Disadvantage: it’s a separate script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With