git 统计代码量
2021-01-07 本文已影响0人
江火渔枫
进入项目目录下(包含.git的目录)
![](https://img.haomeiwen.com/i1151802/480c18ba6a76da56.png)
1.统计sujing在某个时间段内的git新增/删除代码行数
git log --author=sujing --since=2019-01-01 --until=2020-02-01 --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | grep "\(.html\|.java\|.xml\|.properties\)$" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done
![](https://img.haomeiwen.com/i1151802/b48a091790ee4cd8.png)
2.统计该项目所有的代码数
git log --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 }'
![](https://img.haomeiwen.com/i1151802/190177828915f2f9.png)