Git代码统计

所有代码贡献者

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

代码贡献者数量

sort -u 等于 sort | uniq

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

每个人的代码量

git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done

某段时间每个人的代码量

git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --since="2019-3-1" --until="2019-12-10" --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done
# format-1
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --since="2019-3-1" --until="2019-12-10" --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { if(loc>0)printf "added lines: %s\t, removed lines: %s\t, total lines: %s\t", add, subs, loc }' -; echo "\t"; done
# format-2 展示0
git log --format='%aN' | sort -u | while read name; do echo -en "$name===>\t"; git log --author="$name" --pretty=tformat: --since="2019-3-1" --until="2019-12-10" --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { if(loc>0){printf "addedLines: %s\t removedLines: %s\t totalLines: %s\n", add, subs, loc }else{printf "addedLines: 0\t removedLines: 0\t totalLines: 0\n"}}' -;  done 

# format-3 过滤0
git log --format='%aN' | sort -u | while read name; do echo -en "$name===>\t"; git log --author="$name" --pretty=tformat: --since="2019-3-1" --until="2019-12-10" --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { if(loc>0){printf "addedLines: %s\t removedLines: %s\t totalLines: %s\n", add, subs, loc }else{printf "addedLines: 0\t removedLines: 0\t totalLines: 0\n"}}' -;  done |grep -v 'totalLines: 0'
# format-4 过滤0+排序+top10
git log --format='%aN' | sort -u | while read name; do echo -en "$name===>\t"; git log --author="$name" --pretty=tformat: --since="2019-3-1" --until="2019-12-10" --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { if(loc>0){printf "addedLines: %s\t removedLines: %s\t totalLines: %s\n", add, subs, loc }else{printf "addedLines: 0\t removedLines: 0\t totalLines: 0\n"}}' -;  done |grep -v 'totalLines: 0' | sort -k7 -n -r | head -n 10

个人代码量

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}'

某段时间个人代码量

git log --author="$(git config --get user.name)" --pretty=tformat:  --since="2019-5-1" --until="2019-12-10" --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }'

commit 排名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

个人commit 量

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

某段时间某用户的commit量

git log --author=$(git config --get user.name) --since="2019-08-01" --no-merges | grep -e 'commit [a-zA-Z0-9]*' | wc -l

Reference

  • https://blog.csdn.net/hongchangfirst/article/details/46606707
  • https://www.cnblogs.com/gbyukg/archive/2011/12/12/2285419.html

你可能感兴趣的:(Tools)