统计git提交

统计git提交

因为工作需要,需要统计一个时间段指定用户的git提交的次数,代码改变的行数,以及依据commit特殊前缀来统计次数。脚本如下:
 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

# 获取输入参数
email=$1
#example syfangjie@live.cn
start_date=$2
#example 2023-01-01
end_date=$3
#example 2023-10-31
REPO_PATH=$4
#example "/Users/mikusugar/code/test"

# 进入仓库目录
cd $REPO_PATH || exit

# 统计提交次数
commit_count=$(git log --author="$email" --since="$start_date" --until="$end_date" --pretty=oneline | wc -l)
# 统计改变行数
line_count=$(git log --author="$email" --since="$start_date" --until="$end_date" --pretty=tformat: --numstat | awk '{ add += $1 - $2 } END { print add }')

# 统计feat提交次数 前缀为feat的
feat_count=$(git log --author="$email" --since="$start_date" --until="$end_date" --pretty=oneline | grep -c "feat")

# 统计fix提交次数 前缀为fix的
fix_count=$(git log --author="$email" --since="$start_date" --until="$end_date" --pretty=oneline | grep -c "fix")


echo "用户 $email 在当前git仓库的:"
echo "提交次数为 $commit_count 次"
echo "对代码的改变行数为 $line_count 行"
echo "feat 数量 $feat_count 次"
echo "fix 数量 $fix_count 次"