我想列出存储库中每个文件的每个贡献者。
以下是我目前所做的工作:
find . | xargs -L 1 git blame -f | cut -d' ' -f 2-4 | sort | uniq
这是非常慢的。有没有更好的解决方案?
发布于 2012-07-31 18:58:23
我将编写一个小脚本来分析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";
}
}
(编写速度很快;不包括二进制文件等情况。)
如果您将此脚本存储为~/git-contrib.pl
,则可以使用以下命令调用它:
git log --stat=1000,1000 --pretty=format:'%cN' | perl ~/git-contrib.pl
优点:只调用git
一次,这意味着它相当快。缺点:它是一个单独的脚本。
发布于 2012-07-31 20:59:43
以ДМИТРИЙ的回答为基础,我会这样说:
git ls-tree -r --name-only master ./ | while read file ; do
echo "=== $file"
git log --follow --pretty=format:%an -- $file | sort | uniq
done
增强功能是它在历史记录中遵循文件的重命名,并且如果文件包含空格(| while read file
),它将正确运行
发布于 2012-07-31 18:55:27
tldr
for file in `git ls-tree -r --name-only master ./`; do
echo $file
git shortlog -s -- $file | sed -e 's/^\s*[0-9]*\s*//'
done
git ls-tree
获取存储库中所有跟踪的文件。Find
真的是个糟糕的选择。例如,获取当前目录(./
)下分支master
中被跟踪文件的列表:
git ls-tree -r --仅限名称的主控器。/
get shortlog
获取文件编辑器列表(git blame
是overkill):$file shortlog -s -- git
因此,对于来自ls-tree
响应的每个文件,您应该调用shortlog
并根据需要修改其输出。
https://stackoverflow.com/questions/11737681
复制相似问题