Last Updated: April 12, 2019
·
3.768K
· jensnilsson

WTF did I do?!

OMG, It's the end of the month and you look through your time-reports and notice you have a couple of unfilled days/hours and you ask yourself: WTF did I do?!

Time to pull out wtf-did-i-do

#!/bin/bash
# If you're a developer who uses git, this little sucker can help you remember wtf you did on a specific date
find . -type d -maxdepth 1 -exec git --git-dir=./'{}'/.git log --author="$1" --pretty=format:"{} : %an - %ad -> %s" --date=iso --all \; | grep $2
  1. Copy and paste the above code into a file named wtf-did-i-do
  2. Place the file in the same directory you keep all your git-repositories.
  3. Make sure the file is executable by running chmod +x wtf-did-i-do
  4. Execute the script: ./wtf-did-i-do {Name} {Date}
  5. The script will execute a fancy git log command inside every directory and filter {Name} as the author and only output lines that contains {Date}

{Name} Your name.

{Date} is in the ISO 8601 format.

Example:

./wtf-did-i-do Jens 2013-07-04

This would create an output similar to this:

./cool_project : Jens - 2013-07-04 09:30:12 +0100 -> Fixed bug #8
./cool_project : Jens - 2013-07-04 08:40:56 +0100 -> Added feature X

8 Responses
Add your response

Or, juste use the --since and --until options.

over 1 year ago ·

I would like to be able to use those, but I noticed that for some reason they didn't return all commits, there was always 1 missing.

Tested with --since="2013-07-04 00:00:00" --until="2013-07-04 23:59:59"

over 1 year ago ·

You don't have to specify the entire date. Haver you tried with --since=2.days.ago --until=yesterday ?

over 1 year ago ·

Ran a small test with specifying it that way just now.

On Apr 11 2013 I have 6 commit in a repo.

Using git log --pretty=format:"%an - %ad -> %s" --since=87.days.ago --until=86.days.ago:

Jens - Thu Apr 11 08:01:10 2013 +0200 -> Remove donate link in readme
Jens - Thu Apr 11 07:57:32 2013 +0200 -> Updated readme
Jens - Thu Apr 11 00:17:48 2013 +0200 -> Updated readme
Jens - Wed Apr 10 23:49:18 2013 +0200 -> Added a small instructions section to markdown reame
Jens - Wed Apr 10 23:45:37 2013 +0200 -> Added function to render the map in a theme.

3 commits I'm after and a couple of unwanted ones from the day before.

Using git log --pretty=format:"%an - %ad -> %s" --since=86.days.ago --until=85.days.ago:

Jens - Thu Apr 11 20:55:14 2013 +0200 -> Added link to the wordpress.org plugin page
Jens - Thu Apr 11 20:51:13 2013 +0200 -> Added some more tags
Jens - Thu Apr 11 20:50:33 2013 +0200 -> Added screenshot descriptions

Just 3 commits from the date I'm after (I have 0 commits in this repo on the 12th).

Based on the timestamps of the commit messages, this makes me think that the --since and --until flags flags include commit-messages since/until 12:00 respectively.

over 1 year ago ·

I think you might have different commit and author dates. Git-log by default shows the author date and so does your log format; whereas --since and --until seem to filter by commit date.

over 1 year ago ·

Very nice, I made a small change to weed out non git directories:

#!/bin/bash
for D in $(find . -maxdepth 1 -type d); do
  if [ -d "$D/.git" ]; then
    git --git-dir=./"$D"/.git log --author="$1" --pretty=format:"$D : %an - %ad -> %s" -    -date=iso --all | grep $2
  fi
done
over 1 year ago ·

I updated this slightly, based on @jensnilsson's latest comments:

#!/bin/bash

function usage() {
  echo 'Usage: what-did-i-do {options}'
  echo
  echo 'OPTIONS:'
  echo '    -a   author/committer        (defaults to Jason Rogers)'
  echo '    -s   since such date         (defaults to 7.days.ago)'
  echo '    -u   until such date         (defaults to today)'
  echo '    -o   author output format    (one of short, full, initials -- defaults to initials)'
  echo
  echo '-s and -u accepts any Git date: 2013-03-01, 7.days.ago, today, yesterday'
  exit 0
}

SINCE='7.days.ago'
UNTIL='today'
AUTHOR='<put your author name here>'
AUTHOR_OUTPUT='initials'

while getopts “ha:s:o:u:” OPTION
do
  case $OPTION in
    h)
      usage
      exit 1
        ;;
    a)
      AUTHOR=$OPTARG
      ;;
    o)
      AUTHOR_OUTPUT=$OPTARG
      ;;
    s)
      SINCE=$OPTARG
      ;;
    u)
      UNTIL=$OPTARG
      ;;
    ?)
      usage
      exit
      ;;
  esac
done

function initials() {
  echo $AUTHOR | ruby -e'print $stdin.read.split(" ").map{|e| e[0]}.join("")'
}
function shortname() {
  echo $AUTHOR | ruby -e'words = $stdin.read.split(" "); print words[0]; print words[1][0]'
}

case $AUTHOR_OUTPUT in
  full)
    AUTHOR_OUTPUT=$AUTHOR
    ;;
  initials)
    AUTHOR_OUTPUT=$(initials)
    ;;
  short)
    AUTHOR_OUTPUT=$(shortname)
    ;;
  *?)
    echo "unrecognized author output ('$AUTHOR_OUTPUT'); using 'initials'"
    AUTHOR_OUTPUT=$(initials)
    ;;
esac

git log --no-merges --pretty=format:"$AUTHOR_OUTPUT - %ad -> %s" --date-order --date=short --since=$SINCE --until=$UNTIL --author="$AUTHOR"
over 1 year ago ·

Nice. Here's a slightly changed @jacaetevha version with colors, recursion and author output option removed:
https://gist.github.com/jcarsique/5958214

over 1 year ago ·