Loading

git 统计代码量 shell脚本

#!/bin/bash
# 统计代码量
# 使用方法: sh gitstat.sh "2017-11-01" "2017-11-30" "JamKong" ~/workspace/IDEA/项目名/
# 开始时间
startTime=`date -j -f "%Y-%m-%d" $1 +%s`
# 结束时间
endTime=`date -j -f "%Y-%m-%d" $2 +%s`
# 提交代码作者
author=$3
# 项目绝对路径
path=$4||'.'

internalDay=$((($endTime-$startTime)/60/60/24 + 1))
echo "统计总天数:"$internalDay ""

cd $path

preTime=$startTime
nextTime=$startTime
echo "提交者 $3: " 
for (( i=1;i<=$internalDay;i++));do
    temp=$nextTime
    nextTime=`date -r $(( $nextTime + 86400)) +%s`
    preTime=$temp
    echo `date -r $preTime +"%Y%m%d"` - `date -r $nextTime +"%Y%m%d" ` ": \c"
    git log --since=$preTime --until=$nextTime  --author=$3 --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { printf "added lines: %-15s   |   removed lines: %-15s   |   total lines: %-15s\n", add, subs, loc }'    
done
echo 
echo
echo "汇总:\c"
git log --since=$1  --until=$2 --author=$3 --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 + $2 } END { printf "added lines: %-15s   |   removed lines: %-15s   |   total lines: %-15s\n", add, subs, loc }'    
echo

 

 

统计结果:

 

posted @ 2018-01-07 19:29  JamKong  阅读(990)  评论(0编辑  收藏  举报