【git】Git 指令统计代码行数

  • Post author:
  • Post category:其他



目录


统计代码行数


加过滤条件


统计代码行数

统计当前项目代码行数

git ls-files | xargs cat | wc -l

细分每个文件的代码行数,相当于把上面命令细化:

 git ls-files | xargs wc -l

加过滤条件

以下绝大部分摘自:https://blog.csdn.net/qq_39529663/article/details/107763133

1、统计某个时间段内的代码行数;

–since=统计开始时间

–until=统计结束时间

git log –since=2020-01-01 –until=2020-07-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 }’


2、统计某个人某个时间段内的代码行数;

–author=代码提交人/用户名

–since=统计开始时间

–until=统计结束时间


git log –author=username –since=2020-01-01 –until=2020-07-01 –format=’%aN’ | sort -u | while read name; do echo -en “KaTeX parse error: Undefined control sequence: \t at position 5: name\̲t̲”; git log –au…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


3、统计每个用户的所有提交代码行数(包括增、删、修改等)

git log –format=’%aN’ | sort -u | while read name; do echo -en “KaTeX parse error: Undefined control sequence: \t at position 5: name\̲t̲”; git log –au…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


4、仓库提交者排名前 5(如果看全部,去掉 head 管道即可)

git log –pretty=’%aN’ | sort | uniq -c | sort -k1 -n -r | head -n 5

5、统计某个用户的所有提交代码行数

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 }’


6、统计代码提交的人数,也称:统计仓库提交贡献者

git log –pretty=’%aN’ | sort -u | wc -l


7、统计总提交次数

git log –oneline | wc -l


8、统计所有Java代码总行数提交修改的信息(有明细展示)

find . “(” -name “*.java” “)” -print | xargs wc -l


9、统计所有其他文件总行数提交修改的信息(有明细展示)

find . “(” -name “.m” -or -name “.mm” -or -name “.cpp” -or -name “.h” -or -name “.rss” “)” -print | xargs wc -l

可以按需要添加对应的文件后缀:

-or -name “.文件后缀”


10、统计所有文件提交记录明细

git ls-files | xargs wc -l


11、查看最近几次的提交记录

git log -p -2

-2可修改数字,查看最近几次的提交记录



版权声明:本文为bandaoyu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。