查看git上的個(gè)人代碼量:
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 }' -
git log --since="2020-01-01" --before="2020-12-31" --author="username" \
--pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "新增行數(shù): %s, 移除行數(shù): %s, 總行數(shù): %s\n", add, subs, loc }'
統(tǒng)計(jì)每個(gè)人增刪行數(shù):
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 log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --since ==2020-01-01 --until=2020-12-31 --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
查看倉(cāng)庫(kù)提交者排名前 5:
#如果看全部锣尉,去掉 head 管道即可
git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5
#倉(cāng)庫(kù)提交者(郵箱)排名前 5
git log --pretty=format:%ae | gawk -- '{ ++c[$0]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }' | sort -u -n -r | head -n 5
貢獻(xiàn)者統(tǒng)計(jì):
git log --pretty='%aN' | sort -u | wc -l
提交數(shù)統(tǒng)計(jì):
git log --oneline | wc -l
#統(tǒng)計(jì)代碼行數(shù)命令如下:
git log --since ==2020-01-01 --until=2020-12-31 | wc -l
添加或修改的代碼行數(shù):
git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/'
使用gitstats
git log 參數(shù)說(shuō)明:
--author 指定作者
--stat 顯示每次更新的文件修改統(tǒng)計(jì)信息,會(huì)列出具體文件列表
--shortstat 統(tǒng)計(jì)每個(gè)commit 的文件修改行數(shù)琉兜,包括增加邻吞,刪除副硅,但不列出文件列表:
--numstat 統(tǒng)計(jì)每個(gè)commit 的文件修改行數(shù)水泉,包括增加拯杠,刪除掏婶,并列出文件列表:
-p 選項(xiàng)展開(kāi)顯示每次提交的內(nèi)容差異,用 -2 則僅顯示最近的兩次更新
例如:git log -p -2
--name-only 僅在提交信息后顯示已修改的文件清單
--name-status 顯示新增潭陪、修改雄妥、刪除的文件清單
--abbrev-commit 僅顯示 SHA-1 的前幾個(gè)字符最蕾,而非所有的 40 個(gè)字符
--relative-date 使用較短的相對(duì)時(shí)間顯示(比如,“2 weeks ago”)
--graph 顯示 ASCII 圖形表示的分支合并歷史
--pretty 使用其他格式顯示歷史提交信息茎芭∫灸ぃ可用的選項(xiàng)包括 oneline,short梅桩,full壹粟,fuller 和 format(后跟指定格式)
例如: git log --pretty=oneline ; git log --pretty=short ; git log --pretty=full ; git log --pretty=fuller
--pretty=tformat: 可以定制要顯示的記錄格式,這樣的輸出便于后期編程提取分析
例如:git log --pretty=format:""%h - %an, %ar : %s""
下面列出了常用的格式占位符寫法及其代表的意義宿百。
選項(xiàng) 說(shuō)明
%H 提交對(duì)象(commit)的完整哈希字串
%h 提交對(duì)象的簡(jiǎn)短哈希字串
%T 樹(shù)對(duì)象(tree)的完整哈希字串
%t 樹(shù)對(duì)象的簡(jiǎn)短哈希字串
%P 父對(duì)象(parent)的完整哈希字串
%p 父對(duì)象的簡(jiǎn)短哈希字串
%an 作者(author)的名字
%ae 作者的電子郵件地址
%ad 作者修訂日期(可以用 -date= 選項(xiàng)定制格式)
%ar 作者修訂日期趁仙,按多久以前的方式顯示
%cn 提交者(committer)的名字
%ce 提交者的電子郵件地址
%cd 提交日期
%cr 提交日期,按多久以前的方式顯示
%s 提交說(shuō)明
--since 限制顯示輸出的范圍垦页,
例如: git log --since=2.weeks 顯示最近兩周的提交
選項(xiàng) 說(shuō)明
-(n) 僅顯示最近的 n 條提交
--since, --after 僅顯示指定時(shí)間之后的提交雀费。
--until, --before 僅顯示指定時(shí)間之前的提交。
--author 僅顯示指定作者相關(guān)的提交痊焊。
--committer 僅顯示指定提交者相關(guān)的提交盏袄。