[Git] git代码统计

copy : https://www.cnblogs.com/liyropt/archive/2012/12/31/2841053.html

命令行

查看git上的个人代码量:

git log --author="username" --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 }' -

结果示例:(记得修改 username)

added lines: 120745, removed lines: 71738, total lines: 49007

统计每个人增删行数

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

结果示例

Max-laptop    added lines: 1192, removed lines: 748, total lines: 444 chengshuai added lines: 120745, removed lines: 71738, total lines: 49007 cisen added lines: 3248, removed lines: 1719, total lines: 1529 max-h added lines: 1002, removed lines: 473, total lines: 529 max-l added lines: 2440, removed lines: 617, total lines: 1823 mw added lines: 148721, removed lines: 6709, total lines: 142012 spider added lines: 2799, removed lines: 1053, total lines: 1746 thy added lines: 34616, removed lines: 13368, total lines: 21248 wmao added lines: 12, removed lines: 8, total lines: 4 xrl added lines: 10292, removed lines: 6024, total lines: 4268 yunfei.huang added lines: 427, removed lines: 10, total lines: 417 ³Ÿö added lines: 5, removed lines: 3, total lines: 2

查看仓库提交者排名前 5

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

贡献值统计

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

提交数统计

git log --oneline | wc -l

添加或修改的代码行数:

git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/'

使用gitstats

GitStats项目,用Python开发的一个工具,通过封装Git命令来实现统计出来代码情况并且生成可浏览的网页。官方文档可以参考这里。

对于Git开发,有一些可视化的工具,如gitk,giggle等,来查看项目的开发历史。但对于大型的项目,这些简单的可视化工具远远不足以了解项目完整的开发历史,一些定量的统计数据(如每日提交量,行数等)更能反映项目的开发进程和活跃性。GitStats就是这样的工具,它能生成以下统计数据,并以图表形式进行对比

  • 常规的统计:文件总数,行数,提交量,作者数。
  • 活跃性:每天中每小时的、每周中每天的、每周中每小时的、每年中每月的、每年的提交量。
  • 作者数:列举所有的作者(提交数,第一次提交日期,最近一次的提交日期),并按月和年来划分。
  • 文件数:按日期划分,按扩展名名划分。
  • 行数:按日期划分。

GitStats网址:http://gitstats.sourceforge.net/

安装依赖包:Git,Python,Gnuplot。

使用:

  • ./gitstats /mnt/src/git/project ~/public_html/project (Git项目在/mnt/src/git/project下,生成的统计数据放在~/public_html/project目录下)
  • firefox ~/public_html/project/index.html (用firefox查看统计数据)

GitStats提供的一些例子,如Linux Kernel的统计数据(http://gitstats.sourceforge.net/examples/linux-2.6/index.html),下面是截取的一部分结果:

《[Git] git代码统计》

可以看出,在过去的32周中,Linux Kernel每周都有大约1000左右的提交量。下面是作者的列表

《[Git] git代码统计》

可以看到, 大神Linus Torvalds的大名就列在第一个,他贡献了3.98%的提交量,其他有趣的统计数据见上述网址。

    原文作者:demoblog
    原文地址: https://www.cnblogs.com/0616--ataozhijia/p/8081329.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞