代码统计命令
使用git
查看git上的个人代码量:
git log --author="<user>" --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 }'
结果示例:(记得修改 user)
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
查看仓库提交者排名前 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 clone git://github.com/hoxu/gitstats.git
cd gitstats
./gitstats 你的项目的位置 生成统计的文件夹位置
可能会提示没有安装gnuplot画图程序,那么需要安装再执行:
//mac osx
brew install gnuplot
//centos linux
yum install gnuplot
使用cloc
sudo apt-get install cloc
$ cloc . 2737 text files. 2610 unique files. 368 files ignored. github.com/AlDanial/cloc v 1.82 T=7.80 s (304.3 files/s, 111578.7 lines/s) ----------------------------------------------------------------------------------- Language files blank comment code ----------------------------------------------------------------------------------- Java 1629 34790 58716 308190 C++ 91 23021 16761 171747 XML 451 2700 754 170740 C/C++ Header 108 9196 8437 54423 Python 5 573 550 5310 make 67 689 491 1755 diff 2 124 403 426 Gradle 10 25 8 170 Bourne Shell 1 21 22 129 Bourne Again Shell 1 19 20 121 Markdown 4 53 0 63 DOS Batch 1 23 2 59 Windows Resource File 2 0 0 10 ProGuard 2 6 36 0 ----------------------------------------------------------------------------------- SUM: 2374 71240 86200 713143 -----------------------------------------------------------------------------------