34
chenyc
2025-01-09 070ff71561be29e98bbc90e6d77f43f806f5b50b
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
#!/bin/bash
 
# 设置变量
user="chenyc"
start_date="2024-01-01T00:00:00"
end_date="2024-12-30T23:59:59"
 
# 检查当前目录是否是Git仓库
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
  echo "当前目录不是一个Git仓库。请在Git仓库的根目录下运行此脚本。"
  exit 1
fi
 
# 获取提交次数
commit_count=$(git log --author="$user" --since="$start_date" --until="$end_date" --pretty=oneline | wc -l)
 
# 获取代码行数的变化
lines_info=$(git log --author="$user" --since="$start_date" --until="$end_date" --pretty=tformat: --numstat | awk '{ add += $1; del += $2; net += $1 - $2 } END { printf "%s,%s,%s", add, del, net }')
IFS=',' read lines_added lines_deleted lines_changed <<< "$lines_info"
 
# 输出结果
echo "日期: $start_date ~ $end_date"
echo "用户: $user"
echo "提交次数: $commit_count"
echo "增加的代码行数: $lines_added"
echo "删除的代码行数: $lines_deleted"
echo "净变化的代码行数: $lines_changed"