shell脚本按时间统计git代码量
统计代码的shell脚本,可按时间统计,可按作者统计,注释都有,请各位看官按需使用,后续会将python脚本写完奉上
脚本来了
- 按时间统计代码今年代码的增量,减量,和剩余量,不多说,直接上脚本
#!/bin/bash
################################
# function: getCodeCount()
# usage: getCodeCount dir
# param:
# dir就是目录名称
################################
# 获取代码今年代码的增量,减量,和剩余量
getCodeCount() {
cd ${dir}
echo ${dir} >> /root/count.txt
git log --since==2021-01-01 --until=2021-12-31 --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total year lines: %s\n", add, subs, loc }' >> /root/count.txt
git log --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "total lines: %s\n", loc }' >> /root/count.txt
cd ..
}
##################################
# usage: sh codeCount.sh
# comments: 需要在项目代码的最外层目录中执行
##################################
# 获取当前所有项目的目录名称
for dir in `ls`
do
if [ -d $dir ];then
echo $dir
getCodeCount $dir
fi
done
- 按照作者统计时间内代码的增量和总量
#!/bin/bash
###############################
# function: yearCodeCountByAuthor()
# usage: codeCountByAuthor name
# param:
# name: 是git中解析出来的作者
##############################
# 获取2021年每个作者所提交代码的量
yearCodeCountByAuthor() {
git log --author=$1 --since==2021-01-01 --until=2021-12-31 --pretty=tformat: --numstat | grep -E '.java|.xml|.vue|.html|.js|.css|.cs|.h|.m|.swift' | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total year lines: %s\n", add, subs, loc }' >> /root/countByAuthor.txt
}
###############################
# function: codeCountByAuthor()
# usage: codeCountByAuthor name
# param:
# name: 是git中解析出来的作者
##############################
# 获取每个作者所提交的代码总量
codeCountByAuthor() {
git log --author=$1 --pretty=tformat: --numstat | grep -E '.java|.xml|.vue|.html|.js|.css|.cs|.h|.m|.swift' | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "total lines: %s\n", loc }' >> /root/countByAuthor.txt
}
################################
# function: getCodeCount()
# usage: getCodeCount dir
# param:
# dir就是目录名称
################################
# 获取代码中的所有作者
getCodeCount() {
cd ${dir}
git log --format='%aN' | sort -u | while read name
do
echo -en "${dir}\t" >> /root/countByAuthor.txt
echo -en "$name\t" >> /root/countByAuthor.txt
yearCodeCountByAuthor $name
done
cd ..
}
##################################
# usage: sh codeCount.sh
# comments: 需要在项目代码的最外层目录中执行
##################################
# 获取当前所有项目的目录名称
for dir in `ls`
do
if [ -d $dir ];then
echo $dir
getCodeCount $dir
fi
done