Last Updated: February 25, 2016
·
1.246K
· reactiveraven

Generate timesheet CSVs from git log

Copy paste the following to your ~/.bash_aliases:

function csvgit {
        since="9am";
        author="ReactiveRaven";
        directory="~/Code";

        pushd $directory > /dev/null;
        find . -maxdepth 2 -name ".git" |
        tr "/" "\n" | grep -v "^\.$" | grep -v "^\.git$" |
        while read line;
        do
                pushd "$line" > /dev/null;
                git log --all --since="${1:-$since}" --pretty=format:'%ai,%s' --author="${2:-$author}" | sed -E "s/[0-9]{4}-[0-9]{2}-[0-9]{2} //;s/ \+0000//;s/, #/,#/g;"
                popd > /dev/null;
        done | sort;
        popd > /dev/null;
}

and reload your aliases source ~/.bash_aliases.

Usage:

csvgit "9am last thursday" "LaughingMan"
# all commits since last thursday for LaughingMan
csvgit
# all commits since 9AM for 'me'

Don't forget to update the author= and since= to something more useful for you to save typing it out longhand each time, and directory= to point to where you keep your git projects.

To include the name of the project folder in the commit message, tack this onto the end of the sed command:

s/,/,$line:/;