git 统计分支个数_统计Git版本库每个人提交次数和代码的增加和删除行数脚本...

#!/bin/bash

# 统计后台的总的提交次数、增加、删除、留存代码行数

# 统计按照自然月进行或者指定时段进行 $1 为月份(1-12)

#### 定义分支 ####

if [ $2 = "" ] ; then

Branch=develop

else

Branch=$2

fi

#### 定义版本库 ####

#git_repo=cdc.txt

### 当前目录###

if [ $(echo $0 | grep '^/') ]; then

cur_dir=$(dirname $0)

else

cur_dir=$(pwd)/$(dirname $0)

fi

### 定义使用文件###

repo_file=$cur_dir/cdc.txt #版本库定义

commit_file=$cur_dir/commit.txt #提交次数明细

total_file=$cur_dir/total.txt #每人提交次数汇总

detail_file=$cur_dir/detail.txt #每人提交行数明细

everyone_file=$cur_dir/every.txt

### 接收月份参数###

Month=$1

### 初始化中间文件###

:>$commit_file

:>$detail_file

:>$everyone_file

### 首先统计每个人的提交次数,记录到中间文件

function Count() {

while read git_url

do

echo $git_url

goluk_repo=`echo $git_url |awk -F/ '{print $NF}'`

cd $goluk_repo

git checkout $Branch

git pull

git log --pretty='%aN' --since ==2016-$Month-01 --until=2016-$Month-31 | sort | uniq -c | sort -k1 -n -r >> $commit_file

cd ../

done < $repo_file

}

### 代码提交行数

function Codelines() {

while read git_url

do

echo $git_url

goluk_repo=`echo $git_url |awk -F/ '{print $NF}'`

cd $goluk_repo

git pull

git checkout $Branch

# 统计各版本总行数

git log --author=^.* --pretty=tformat: --numstat --since=2016-$Month-01 --until=2016-$Month-31 |\

awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } \

END { print add,subs,loc ,repo_name }' repo_name=$goluk_repo - >> $detail_file

### debug begin

###git log --author=^.* --pretty=tformat:%aN --numstat --since=2016-$Month-01 --until=2016-$Month-31 |\

### awk '!/^$/' >> $cur_dir/every2.txt

## debug end

# 记录各人代码、增加行数、删除行数明细

git log --pretty='tformat:%aN' --numstat --since=2016-$Month-01 --until=2016-$Month-31 >>$everyone_file

cd ../

done < $repo_file

}

#awk '{sum[$2]+=$1}END{for(i in sum)print i ,sum[i]}' scrope.txt |sort -k2 -nr >

Count $Month

### 计算总提交次数

awk '{sum[$2]+=$1}END{for(i in sum)print i ,sum[i]}' $commit_file |sort -k2 -nr > $total_file

Codelines $Month

### 汇总提交数

awk '{cnt+=$2}END{printf "%-20d%10d\n",Mon,cnt}' Mon=$Month $total_file

### 汇总代码行数

#awk '{adds+=$1;removes+=$2;saves+=$3}END{print adds,removes,saves}' $detail_file

### 汇总计算各人的代码行数

### 删除空行

awk '!/^$/' $everyone_file |\

### 计算

awk '{if($1 ~ /^[a-zA-Z]+$/) {if(NR==1){printf "%20s",$1 }else {printf "\n%20s%8d%8d",$1,adds,dels;adds=0;dels=0}} \

else{adds=adds+$1;dels=dels+$2;next} }' |\

### 汇总

awk '{cnt[$1]++;name[$1]=$1;adds[$1]+=$2;dels[$1]+=$3}END{for(i in name) printf "%-20s%10d%10d%10d%10d\n", name[i],cnt[i],adds[i],dels[i],adds[i]-dels[i]}'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值