Skip to content

Instantly share code, notes, and snippets.

@scmx
Last active February 23, 2023 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scmx/94486bb7fdb8069f55e5d89cec32b256 to your computer and use it in GitHub Desktop.
Save scmx/94486bb7fdb8069f55e5d89cec32b256 to your computer and use it in GitHub Desktop.
git-allcommits List all commits made by you in all repositories in the last month #git #commits #multirepo

git-allcommits List all commits made by you in all repositories in the last month

#!/usr/bin/env bash

# List all commits made by you in all repositories in the last month

set -euo pipefail

commits=()

for repopath in "$HOME/Dev/"*; do
	if [[ ! -d "$repopath" ]]; then
		continue
	fi

	if [[ ! -d "$repopath/.git" ]]; then
		continue
	fi

	cd "$repopath"

  name=$(git config --get user.name)
  after=$(date -v-1m '+%Y-%m-%d')
	lines=$(git log --all --author "$name" --format="%aI %cI %s" --after $after)

	if [[ -z "$lines" ]]; then
		continue
	fi

	while read -r line; do
		author_timestamp=$(cut -d ' ' -f1 <<< "$line")
		committer_timestamp=$(cut -d ' ' -f2 <<< "$line")
		author_date=$(cut -d T -f 1 <<< "$author_timestamp")
		committer_date=$(cut -d T -f 1 <<< "$committer_timestamp")
		author_time=$(cut -c 12-16 <<< "$author_timestamp")
		committer_time=$(cut -c 12-16 <<< "$author_timestamp")
		title=$(cut -d ' ' -f3- <<< "$line")

		commits+=("$author_date $author_time $title")

		if [[ "$author_date" != "$committer_date" ]]; then
			commits+=("$committer_date $committer_time $title")
		fi
	done <<< "$lines"
done

for line in "${commits[@]}"; do
	echo "$line"
done | sort
  • Shows --all commits from all branches, so if you amended a commit on a later date it will show up multiple times
  • Checks both author date and committer date, so you will se both when it was originally authored and when it was last committed, if on different dates
  • Assumes that all your git repositories are in $HOME/Dev/, you could add multiple folders there
  • Assumes that all your commits have your user.name as author git config --get user.name
  • To get a date 1 month ago I used date -v-1m '+%Y-%m-%d'. This is macOS specific. For linux you could try date --date='-1 month' '+%Y-%m-%d'.
  • If you are working on many different repos, you might want to print project folder name as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment