shell脚本统计代码量
-
新建一个文件夹 ;如“projects”
-
进入projects文件夹
-
拉取待统计项目 git clone xx
-
创建shell 脚本;如 vim codeSum.sh
-
键盘按 i,进入输入模式,输入
for file in /Users/yilian/git/service/*; do cd $file git pull git log --format='%aN' --after='2019-05-01' --before='2019-06-01' | sort -u | while read name; do echo -en "$name\t"; git log --after='2019-05-01' --before='2019-06-01' --author="$name" --pretty=tformat: --numstat | grep -v vendor | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "%s, %s, %s\n", add, subs, loc }' -; done done
-
点击Esc,跳出命令行模式,输入 :wq (保存并退出)
-
将shell脚本移动到其他目录下,只要不和项目在一个目录下就ok;如不放在projects文件里
-
bash 脚本路径 | awk '{arr[$1]+=$2+$2}END{for (k in arr){print k, arr[k]}}'
注释:
- git log 会按提交时间列出所有的更新,最近的更新排在最上面
- sort -u 全局消重
- aN 作者(author)名字
- –numstat :统计每个commit的文件修改行数,保罗增加,删除,文件列表