shell脚本按时间统计git代码量

shell脚本按时间统计git代码量

统计代码的shell脚本,可按时间统计,可按作者统计,注释都有,请各位看官按需使用,后续会将python脚本写完奉上

脚本来了

  1. 按时间统计代码今年代码的增量,减量,和剩余量,不多说,直接上脚本
#!/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
  1. 按照作者统计时间内代码的增量和总量
#!/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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值