Git-统计每天特定时间区间代码提交次数-非上班时间代码提交

发布时间 2023-12-29 11:45:08作者: 生生灯火半杯月

git-code-specific-time-of-day.sh

#!/bin/bash

total_count=0

# 获取最早的提交日期
first_commit_date=$(git log --pretty=format:'%ad' --date=format:'%Y-%m-%d' | sort | head -n 1)

# 计算当前日期
current_date=$(date +%Y-%m-%d)

# 遍历从最早提交日期到当前日期的所有日期
end=$(( $(date -d "$current_date" +%s) - 1 ))
start=$(( $(date -d "$first_commit_date" +%s) + 86400 ))

while [ $start -le $end ]; do
    date=$(date -d "@$start" +%Y-%m-%d)
    
    # 计算前一天的日期
    previous_date=$(date -d "$date -1 day" +%Y-%m-%d)

    # 统计前一天17:30到当天8:45的提交次数
    commit_count=$(git log --pretty=format:'%H' --since="$previous_date 17:30" --until="$date 08:45" | sort -u | wc -l)

    # 累加到总提交次数
    total_count=$((total_count + commit_count))

    # 更新开始时间
    start=$((start + 86400))
done

echo "Total evening commits across all days: $total_count"