赞同 0
分享

统计项目代码行数命令

简介:一个比较无聊但是很有趣的命令工具,很久没有统计过本地项目代码行数了,离职之前再统计一次看看项目代码数量增长多少了。
  2021.05.12
  Bug Man
  0
  151
  172.17.0.1
  中国.上海
 
 

用两种途径来统计代码数量,一种是硬核的计算文件代码行数,另外一种通过git的server来统计出代码增删改的情况。

# 使用shell命令统计行数
find . -name "*.py" | xargs grep -v "^$" |wc -l

# 注意--author后面的用户名需要改成对应的用户名
# 统计某个人的 增加代码行数 删除代码行数 总共贡献代码行数
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 }' -

# 统计项目每一个参与者  增加代码行数 删除代码行数 总共贡献代码行数
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --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 }' -; done

统计结果