git代碼統計

命令行

查看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)linux

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

結果示例git

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命令來實現統計出來代碼狀況而且生成可瀏覽的網頁。官方文檔能夠參考這裏。github

使用方法

git clone git://github.com/hoxu/gitstats.git
cd gitstats
./gitstats 你的項目的位置 生成統計的文件夾位置

可能會提示沒有安裝gnuplot畫圖程序,那麼須要安裝再執行:npm

//mac osx
brew install gnuplot
//centos linux
yum install gnuplot

生成的統計文件爲HTML:
2014-8-16-git.jpgsegmentfault

使用cloc

npm install -g cloc

image

參考文章

git代碼行統計命令集
統計本地Git倉庫中不一樣貢獻者的代碼行數的一些方法
使用Git工具統計代碼centos

相關文章
相關標籤/搜索