11.25
This commit is contained in:
40
材料/code/统计git提交.sh
Normal file
40
材料/code/统计git提交.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 存储各分支的总变化行数(新增+删除)
|
||||
declare -A branch_total
|
||||
|
||||
# 遍历所有本地分支(排除 HEAD 指针)
|
||||
for branch in $(git branch | grep -v "HEAD" | sed 's/^\* //'); do
|
||||
echo "============================================="
|
||||
echo "正在统计分支:$branch"
|
||||
echo "============================================="
|
||||
|
||||
# 初始化当前分支的总行数
|
||||
branch_total[$branch]=0
|
||||
|
||||
# 遍历当前分支的所有提交(按时间从早到晚)
|
||||
git log "$branch" --reverse --pretty=format:"%h %ad %an" --date=short | while read commit date author; do
|
||||
# 统计当前提交的新增+删除行数(无变化时输出 0)
|
||||
lines=$(git diff --shortstat "$commit^..$commit" | awk '{print $4+$6}' | head -n1)
|
||||
lines=${lines:-0} # 处理空值(首次提交无父提交时)
|
||||
|
||||
# 累加当前分支的总行数
|
||||
branch_total[$branch]=$((branch_total[$branch] + lines))
|
||||
|
||||
# 输出当前提交的详情(日期 提交人 提交哈希 本次变化行数)
|
||||
echo -e "$date\t$author\t$commit\t$lines"
|
||||
done
|
||||
|
||||
# 输出当前分支的总变化行数
|
||||
echo -e "分支 $branch 总变化行数:${branch_total[$branch]}\n"
|
||||
done
|
||||
|
||||
# 输出所有分支的汇总排名(按总变化行数降序)
|
||||
echo "============================================="
|
||||
echo "所有分支总变化行数汇总(降序)"
|
||||
echo "============================================="
|
||||
for branch in $(printf "%s\n" "${!branch_total[@]}" | sort -nr -k1,1 --compress-program=gzip < <(for b in "${!branch_total[@]}"; do echo "${branch_total[$b]} $b"; done)); do
|
||||
total=$(echo "$branch" | awk '{print $1}')
|
||||
branch_name=$(echo "$branch" | awk '{print $2}')
|
||||
echo "$branch_name: $total 行"
|
||||
done
|
||||
Reference in New Issue
Block a user