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),下面是截取的一部分結果:

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

可以看到, 大神Linus Torvalds的大名就列在第一個,他貢獻了3.98%的提交量,其他有趣的統計數據見上述網址。
