git log: only show yesterday's commit
Asked Answered
S

3

17

git log --since=yesterday --until=today doesn't work because it will include today's commits.

git log --since=yesterday --until=yesterday doesn't work because it will not show anything at all.

I'm assuming that "yesterday" translates to 12:01am of the previous date, and "today" translates to the current hour. That can make sense to some degree, but it is very unhelpful for me right now.

I also want this to be in a script. So I can't hardcode the dates/times. Is the only option really to programmatically calculate yesterday's date and manually pass the hour as well?

EDIT:

I noticed the following. In the source code for the most recent version of git, it appears that "yesterday" (see code here) means 24*60*60 seconds before the current time. So depending on how precise you need to be, that could matter. Right above that line in the code you see that "today" does mean right now

Shaeffer answered 3/7, 2014 at 13:42 Comment(0)
S
26

I was looking for a way to show all commits since "yesterday" and was having trouble to get the commits older than 24 hours ago (if it's 11am and I just use --since=yesterday, I wouldn't get commits made e.g. at 10:30am, as already pointed). Using

git log --since=yesterday.0:00am

or, more conveniently

git log --since=yesterday.midnight

solved it. Kudos to "tinifni" for his very useful gist: https://gist.github.com/tinifni/3756796

Shearwater answered 24/11, 2016 at 14:10 Comment(1)
Maybe git log --since=yesterday.midnight --until=midnight?Easement
E
4

You don't have to compute the date :

git log --since=yesterday --before=0am

However, be careful of what git exactly considers to be the start of the day. Little demonstration :

git log --since=yesterday --before=0am | grep Date:
Date:   Wed Jul 2 18:01:28 2014 +0200
Date:   Wed Jul 2 17:59:39 2014 +0200
Date:   Wed Jul 2 17:59:22 2014 +0200
Date:   Wed Jul 2 17:02:37 2014 +0200
Date:   Wed Jul 2 16:53:52 2014 +0200

git log  | grep Date:
Date:   Wed Jul 2 18:01:28 2014 +0200
Date:   Wed Jul 2 17:59:39 2014 +0200
Date:   Wed Jul 2 17:59:22 2014 +0200
Date:   Wed Jul 2 17:02:37 2014 +0200
Date:   Wed Jul 2 16:53:52 2014 +0200
Date:   Wed Jul 2 16:02:49 2014 +0200
Date:   Wed Jul 2 15:41:15 2014 +0200
Date:   Wed Jul 2 15:16:47 2014 +0200
Date:   Wed Jul 2 14:34:15 2014 +0200
Date:   Wed Jul 2 10:48:25 2014 +0200
Date:   Wed Jul 2 10:44:59 2014 +0200

So apparently the day starts at around 4:30pm at my place! Coincidence? I think not. It is currently 4:30, so as AlexanderBird pointed out, yesterday is 24 hours before the current time in git source code.

Egbert answered 3/7, 2014 at 14:1 Comment(5)
Do you have any commits that exist for today? If so, I believe those will show up in the results as well. -- at least for git v1.7.9 and v1.8.3.msysgit.0 Which version of git are you using?Shaeffer
You are right, let me investigate, I believe this used to work. I use git 2.0.1Egbert
@AlexanderBird be careful though, on my machine days start at awkward times for git! :)Egbert
what do you mean by awkward times? You can explain as an edit to the answer if you think that's helpful to others as wellShaeffer
Nice find. You can evaluate your productivity with git log --after=tea !Egbert
S
1
#!/usr/bin/ruby
require 'date'
today = Date.today.strftime("%m/%d/%Y")
yesterday = Date.today.prev_date.strftime("%m/%d/%Y")
puts `git log --since=#{yesterday} --until="#{today}"`

Note, that I believe this has more accuracy than merely passing the string "yesterday" to git cli because "yesterday" only means 24*60*60 seconds before current time.

Shaeffer answered 3/7, 2014 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.