每个文件的Git贡献者

log*_*og0 8 git sh

我想列出存储库中每个文件的每个贡献者.

这是我现在所做的:

find . | xargs -L 1 git blame -f | cut -d' ' -f 2-4 | sort | uniq
Run Code Online (Sandbox Code Playgroud)

这很慢.有更好的解决方案吗?

Cha*_*esB 6

以ДМИТРИЙ的答案为基础,我会说以下内容:

git ls-tree -r --name-only master ./ | while read file ; do
    echo "=== $file"
    git log --follow --pretty=format:%an -- $file | sort | uniq
done
Run Code Online (Sandbox Code Playgroud)

增强是它在历史记录中跟随文件重命名,并且如果文件包含空格(| while read file),则行为正确


igo*_*gor 5

我会写一个小脚本来分析git log --stat --pretty=format:'%cN'; 类似的东西:

#!/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";
    }
}
Run Code Online (Sandbox Code Playgroud)

(写得很快;不包括二进制文件之类的情况。)

如果您存储了此脚本,例如 as ~/git-contrib.pl,您可以使用以下命令调用它:

git log --stat=1000,1000 --pretty=format:'%cN' | perl ~/git-contrib.pl
Run Code Online (Sandbox Code Playgroud)

优点:git只调用一次,这意味着它相当快。缺点:它是一个单独的脚本。