-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-stats.sh
More file actions
executable file
·38 lines (31 loc) · 1.47 KB
/
git-stats.sh
File metadata and controls
executable file
·38 lines (31 loc) · 1.47 KB
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
33
34
35
36
37
38
#!/bin/bash
# Git daily stats — lines added / removed / net per day + total summary
echo ""
echo "=== Git Daily Stats ==="
echo ""
printf "%-12s %8s %8s %8s\n" "Date" "Added" "Removed" "Net"
printf "%-12s %8s %8s %8s\n" "----------" "------" "------" "------"
total_added=0
total_removed=0
git log --reverse --format="%ad" --date=short | sort -u | while read -r day; do
added=$(git log --after="$day 00:00:00" --before="$day 23:59:59" --date=short --numstat --pretty="" | awk '{ if ($1 != "-") s += $1 } END { print s+0 }')
removed=$(git log --after="$day 00:00:00" --before="$day 23:59:59" --date=short --numstat --pretty="" | awk '{ if ($2 != "-") s += $2 } END { print s+0 }')
net=$((added - removed))
printf "%-12s %8d %8d %8d\n" "$day" "$added" "$removed" "$net"
total_added=$((total_added + added))
total_removed=$((total_removed + removed))
done
echo ""
echo "=== Total Summary ==="
echo ""
total_added=$(git log --numstat --pretty="" | awk '{ if ($1 != "-") s += $1 } END { print s+0 }')
total_removed=$(git log --numstat --pretty="" | awk '{ if ($2 != "-") s += $2 } END { print s+0 }')
total_net=$((total_added - total_removed))
total_commits=$(git rev-list --count HEAD)
active_days=$(git log --format="%ad" --date=short | sort -u | wc -l | tr -d ' ')
printf "Added: %8d lines\n" "$total_added"
printf "Removed: %8d lines\n" "$total_removed"
printf "Net: %8d lines\n" "$total_net"
printf "Commits: %8d\n" "$total_commits"
printf "Active days: %4d\n" "$active_days"
echo ""