1. 统计提交的作者
git log --pretty='%aN' | sort | uniq -c |awk '{print $2}'
2. 统计代码量
git log --author="uer_name" --since ==2017-05-11 --until=2018-03-07 --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -
3. 使用图形化工具
安装gitstatus
git clone git://github.com/hoxu/gitstats.git
cd gitstats
./gitstats 你的项目的位置 生成统计的文件夹位置
生成的 html文件可web上打开index.html
4,统计每次的提交的commit ID,author email,日期
git log --pretty=format:"%H:%cd:%ce" --date=short
代码实现计算每个author在指定的时间的提交代码统计或每个commit 的代码修改量统计
#!/usr/bin/env bash
START_TIME=2012-01-01
END_TIME=2012-01-11
#count code by author
function count_author()
{
authors=$(git log --pretty='%aN' | sort | uniq -c |awk '{print $2}')
for user in $authors
do
echo "<$user> `git log --author=$user --since ==$START_TIME --until=$END_TIME --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s ;removed lines: %s ;total lines: %s\n",add,subs,loc }' -`"
done
echo "<TOTAL> `git log --since ==$START_TIME --until=$END_TIME --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s ;removed lines: %s ;total lines: %s\n",add,subs,loc }' -`"
}
#count code by per commit
function count_per_commit()
{
all_commits=$(git log --since ==$START_TIME --until=$END_TIME --pretty=format:"%H:%cd:%ce:" --date=short)
for commit in $all_commits
do
commit_id=$(echo "$commit"|awk -F ":" '{print $1}')
commit_date=$(echo "$commit"|awk -F ":" '{print $2}')
commit_email=$(echo "$commit"|awk -F ":" '{print $3}')
echo "<$commit_email>--<$commit_date>-- `git show $commit_id --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s ;removed lines: %s ;total lines: %s\n",add,subs,loc }' -`"
done
}
count_author
count_per_commit