Skip to content

Instantly share code, notes, and snippets.

@jasperf
Last active September 8, 2025 01:56
Show Gist options
  • Save jasperf/c8ff94d8f1f5a63463e0b544c8d11502 to your computer and use it in GitHub Desktop.
Save jasperf/c8ff94d8f1f5a63463e0b544c8d11502 to your computer and use it in GitHub Desktop.
Git workday summary using commits and session gap > 1 hr
#!/bin/bash
# Work Log Script - Shows git commits as "tasks" and calculates work sessions
#
# Usage:
# ./docs/work.sh [YYYY-MM-DD] # default today if no date given
if [ $# -eq 0 ]; then
DAY=$(date +%Y-%m-%d)
else
DAY="$1"
fi
REPO_NAME=$(basename `git rev-parse --show-toplevel 2>/dev/null`)
THRESHOLD=3600 # 1 hour gap in seconds
echo "======================================"
echo " Work Log Report"
echo " Repository : ${REPO_NAME:-Unknown}"
echo " Date : $DAY"
echo "======================================"
echo
# Collect commits but hide PR merges
COMMITS=$(git log --since="$DAY 00:00" --until="$DAY 23:59" \
--pretty=format:"%ad|%an|%s" --date=iso | grep -v "Merge pull request" | sort)
if [ -z "$COMMITS" ]; then
echo "❌ No tasks found for $DAY"
exit 0
fi
echo "πŸ“ Tasks:"
echo "$COMMITS" | awk -F"|" '
BEGIN { last_author="" }
{
time=$1; author=$2; msg=$3
split(time, parts, " ")
hhmm=substr(parts[2],1,5) # extract HH:MM
tz=parts[3]
if (author != last_author) {
print ""
print "πŸ‘€ " author " (" tz ")"
last_author=author
}
printf " %s %s\n", hhmm, msg
}'
echo
# Time calculation (sessions with 1h gap)
echo "$COMMITS" | awk -F"|" -v threshold=$THRESHOLD -v day="$DAY" '
{
commit_time=$1; author=$2
if (system("command -v gdate >/dev/null 2>&1") == 0) {
cmd="gdate -d \"" commit_time "\" +%s"
} else {
cmd="date -j -f \"%Y-%m-%d %H:%M:%S %z\" \"" commit_time "\" +%s"
}
cmd | getline epoch; close(cmd)
times[NR]=epoch
commits[NR]=commit_time
authors[NR]=author
}
END {
total=0; sessions=0; session_start=times[1]
for (i=2; i<=NR; i++) {
gap=times[i]-times[i-1]
if (gap > threshold) {
total += times[i-1]-session_start
sessions++
session_start=times[i]
}
}
total += times[NR]-session_start
sessions++
diff_hours = total / 3600
print "πŸ“Š Time Summary:"
printf " First task : %s | %s\n", commits[1], authors[1]
printf " Last task : %s | %s\n", commits[NR], authors[NR]
printf " Sessions : %d (gap >1h starts new session)\n", sessions
printf " Estimated work time : %.1f hours\n", diff_hours
}'

Work Summary Tools

Daily Work Summary Script

Use this git command to generate a summary of work done for any given day:

# Get today's commits summary
git log --since="$(date +%Y-%m-%d) 00:00:00" --until="$(date +%Y-%m-%d) 23:59:59" --oneline --author="$(git config user.name)"

# Get detailed stats for today's commits
git log --since="$(date +%Y-%m-%d) 00:00:00" --until="$(date +%Y-%m-%d) 23:59:59" --stat --author="$(git config user.name)"

# Get first and last commit times to estimate work hours
echo "First commit:" && git log --since="$(date +%Y-%m-%d) 00:00:00" --until="$(date +%Y-%m-%d) 23:59:59" --format="%ai %s" --author="$(git config user.name)" | tail -1
echo "Last commit:" && git log --since="$(date +%Y-%m-%d) 00:00:00" --until="$(date +%Y-%m-%d) 23:59:59" --format="%ai %s" --author="$(git config user.name)" | head -1

Custom Date Range

For specific dates, replace $(date +%Y-%m-%d) with the desired date in YYYY-MM-DD format:

# Example for September 5, 2025
git log --since="2025-09-05 00:00:00" --until="2025-09-05 23:59:59" --oneline --author="$(git config user.name)"

Work Summary Template

When generating work summaries, use this template:

## Work Summary - [Date]

**Estimated Hours Worked**: [Start Time] - [End Time] ([Duration])

### Major Tasks Completed:

**1. Task Name ([Time])**
- Description of work done
- Files/features modified
- Version updates

**2. Task Name ([Time])**
- Description of work done
- Files/features modified

### Files Modified:
- **Category**: file1, file2, file3
- **Category**: file4, file5

### Pull Requests Merged: [Number]
Brief description of workflow approach.

**Current Theme Version**: [Version]

Usage Notes

  • The script uses git config user.name to filter commits by author
  • Times are shown in the repository's configured timezone
  • Use git log --help for additional formatting options
  • Consider using --no-merges flag to exclude merge commits if needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment