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"
标签:-%,count,Git,+%,代码,start,提交,date
From: https://www.cnblogs.com/a999/p/17934546.html