最近因为需要填写软著,需要填写代码行数,找了找相关的方法,很简单,整理后如下:
1、根据用户名来统计
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 }' -
把username换成自己的用户名就可以了
2、按照一段时间来统计
git log --since=2022-09-28 --until=2022-11-26 --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 }'
把时间切换成自己想要统计的时间段就可以了
3、按照用户名和时间段来统计
git log --author="username" --since=2021-12-31 --until=2022-08-01 --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 }' -
结果预览:
added lines: 138355, removed lines: 112351, total lines: 26004