Skip to content

Instantly share code, notes, and snippets.

@kvz
Created June 21, 2015 18:46
Show Gist options
  • Save kvz/bbb61b61e4ffab48e7f6 to your computer and use it in GitHub Desktop.
Save kvz/bbb61b61e4ffab48e7f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Git Timetracker. Copyright Kevin van Zonneveld (kvz.io)
# License under MIT
#
# This file
#
# - can be run inside a git repository to get a list on what hours work took place (for billing)
# - takes 1 argument: since. It defaults to "2 months"
#
# Usage:
#
# cd repo
# git-timetracker.sh 1 month
#
# Remarks:
#
# - Since we can't use a custom dateformat but really want to, the hack is to
# use iso format, and add backspace characters (%x08)
#
# Possible output:
#
# 2013-03-30 14:02 4bf9607 [email protected] Allow the egrep to fail without bailing out
# 2013-03-28 01:29 9120b9e [email protected] When cron fails, fallback to fallback nameservers :) Fixes #1
# 2013-03-27 13:42 d0b0df2 [email protected] Improve docs
# 2013-03-27 13:10 68c4314 [email protected] Initial import of dns-failover.sh
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Optionally set how long to travel back in time
since="${@:-2 months}"
git --no-pager log \
--date=iso \
--since="${since}" \
--date-order \
--full-history \
--all \
--pretty=tformat:"%C(cyan)%ad%x08%x08%x08%x08%x08%x08%x08%x08%x08 %C(bold red)%h %C(bold blue)%<(22)%ae %C(reset)%s"
@oliverpool
Copy link

A nice trick is to add it to your ~/.gitconfig as an alias:

[alias] 
	timetrack = "!f() { \
         git --no-pager log \
		 	--date=iso \
		 	--since="${1-2 months}$" \
			"${2}" \
		 	--date-order \
		 	--full-history \
		 	--all \
			--pretty=tformat:'%C(cyan)%ad%x08%x08%x08%x08%x08%x08%x08%x08%x08 %C(bold red)%h %C(bold blue)%<(22)%ae %C(reset)%s'; \
       }; f"

You can then type git timetrack, git timetrack "1 day", git timetrack "1 month" --reverse (the arguments are positional, so the duration is required in this case) in any git repository!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment