菜鸟笔记
提升您的技术认知

Git 统计

有时候想统计仓库的情况,比如代码量,贡献者之类的。

1 统计某人的commit数量

git log --author="$(git config --get user.name)" --oneline | wc -l

2 统计某人的代码量

git log --author="$(git config --get user.name)" --pretty=tformat: --numstat | awk '{adds += $1; subs += $2; all += $1 + $2} END {printf "added lines: %s removed lines : %s all lines: %s\n",adds,subs,all}'

3 提交排名top 10

%aN代表只显示commit的author name。也可以使用%ae,使用author email,防止出现重名的情况。然后按照名字或者email排序,之后uniq的时候数count,之后按照第一列的值按照number的方式排序,最后取前10条记录。

 git log --pretty=%aN | sort | uniq -c | sort -k1 -n -r | head -n 10

4 统计有多少个代码贡献者

sort -u 等于 sort | uniq

git log --pretty=%aN | sort -u | wc -l