I am trying to make an alias that, when used, would show all commits since 5 AM. First I found this Stack Overflow answer which got me this far:
git log --since="5am"
Which at first seemed to be exactly what I need, except that after using it for a while, I noticed that if I execute it at any time between 05:00
and 23:59
, I get all the commits that were committed the same day since 5 AM as expected, but if I execute it at any time between 00:00
and 04:59
, I don't get any commits, not even ones that I commit after 12 AM.
So I guess using a time like that with --since
is kind of equivalent to "give me all the commits that were literally committed today AND after 5 AM". What I want is more like "give me all the commits that were committed since the last time it was 5 AM, be it today or yesterday". For example if today I make a commit at 9 AM, I want to be able to see it in the result for the rest of the day, but also tomorrow from 12 AM to 5 AM.
Is there a way to achieve this?
Thanks :)
I think you can handle this by testing the current time inside the since
argument. Something like this will probably work. (Assumes a bash shell.)
git log --since="5am$(if test $(date +%k) -lt 5; then echo ' yesterday'; fi)"