Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git log since yesterday for working days only

Tags:

For my daily standups I like to output my commits for a refresher of what I was working on.

I have the following alias:

standup = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(green)<%an>%Creset' --abbrev-commit --date=relative --committer='me' --all --since='yesterday'

However this does not work for a Monday morning due to the weekend.

Does anyone know how to use git log --since for a set of working days such as Mon - Fri, or Tue - Sat?

like image 298
Cellze Avatar asked Jul 01 '11 11:07

Cellze


1 Answers

Assuming a POSIX-y shell, in my case bash:

function yesterworkday() 
{ 
    if [[ "1" == "$(date +%u)" ]]
    then 
        echo "last friday"
    else
        echo "yesterday"
    fi
}

git log --since="$(yesterworkday)"

Again all credits go to the authors of git for making this insanely easy by accepting "last friday" as a valid date specification to begin with!

PS. to make this a git alias, you need to include bash shell in your alias, I'll edit with a sample in a minute

Edit Putting this logic directly into a git alias proves difficult (with all the quoting required). See here for ideas: .gitconfig alias function call

I fully recommend making a shell script of this, and you could alias the shell script directly like so:

standup = !$HOME/standuplog.sh

or add to one of your $PATH folders and name it git-standup.

like image 166
sehe Avatar answered Sep 20 '22 17:09

sehe