1. 程式人生 > >統計本地Git倉庫中不同貢獻者的程式碼行數的一些方法

統計本地Git倉庫中不同貢獻者的程式碼行數的一些方法

簡單的檢視和統計
1.顯示所有貢獻者及其commit數

git shortlog –numbered –summary

2.只看某作者提交的commit:

git log –author=”eisneim” –oneline –shortstat

顯示行數的統計:

1.Mac,Linux下可以

git log –shortstat –pretty=”%cE” | sed ‘s/\(.*\)@.*/\1/’ | grep -v “^$” | awk ‘BEGIN { line=””; } !/^ / { if (line==”” || !match(line, $0)) {line = $0
“,” line }} /^ / { print line ” # ” $0; line=””}’ | sort | sed -E ‘s/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//’ | awk ‘BEGIN {name=””; files=0; insertions=0; deletions=0;} {if ($1 != name && name != “”) { print name “: ” files ” 個檔案被改變, ” insertions ” 行被插入(+), ” deletions ” 行被刪除(-), ” insertions-deletions ” 行剩餘”; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name “: ” files ” 個檔案被改變, ” insertions ” 行被插入(+), ” deletions ” 行被刪除(-), ” insertions-deletions ” 行剩餘”;}’

2.使用ruby

git ls-files -z | xargs -0n1 git blame -w | ruby -n -e ‘$_ =~ /^.*\((.*?)\s[\d]{4}/; puts $1.strip’ | sort -f | uniq -c | sort -n

3.統計不同程式語言的行數 這一點不是針對git倉庫的,所有的專案都可以,這裡我們使用的工具是:cloc (count lines of code)

//mac osx
brew install cloc
// linux 可以用yum或者apt安裝,當然也可以自己make install
//使用示例:
cd my_project
cloc .
/ –exclude-dir=node_modules,public/lib,public/vendor,public/build –exclude-lang=CSS

非常詳細的統計

要想得到非常詳細的統計,例如提交時間表,程式碼隨時間的增長曲線等,可以使用gitstats

git clone git://github.com/hoxu/gitstats.git
cd gitstats
./gitstats 你的專案的位置 生成統計的資料夾位置

可能會提示沒有安裝gnplot畫圖程式,那麼需要安裝再執行:

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