Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange behavior from git log --since

Tags:

git

I have a test repository with 18 commits. git log | grep Date: returns the following:

Date:   Fri Sep 20 08:04:13 2013 +0200
Date:   Fri Sep 20 08:03:28 2013 +0200
Date:   Fri Sep 20 08:02:05 2013 +0200
Date:   Thu Sep 19 09:53:10 2013 +0200
Date:   Wed Sep 18 17:04:41 2013 +0200
Date:   Wed Sep 18 17:03:36 2013 +0200
Date:   Sat Sep 14 14:42:10 2013 +0200
Date:   Wed Sep 11 10:37:25 2013 +0200
Date:   Fri Aug 30 13:59:43 2013 +0200
Date:   Fri Aug 30 13:56:35 2013 +0200
Date:   Fri Aug 30 11:30:17 2013 +0200
Date:   Thu Aug 29 13:44:28 2013 +0200
Date:   Thu Aug 29 13:34:32 2013 +0200
Date:   Wed Aug 28 14:44:03 2013 +0200
Date:   Wed Aug 28 14:32:44 2013 +0200
Date:   Tue Aug 27 16:18:53 2013 +0200
Date:   Tue Aug 27 16:16:29 2013 +0200
Date:   Tue Aug 27 15:46:04 2013 +0200

I want to get a log from all commits that happened today (20.09.2013), so I tried

git log --since=20-09-2013 | grep Date: 

I get nothing with that. So I searched a bit here on SO and found this question. In the comments it states that

seems so, that it without a time it defaults to the last second of the day.

Okay, no problem. Let's try git log --since=19-09-2013. That returns

Date:   Fri Sep 20 08:04:13 2013 +0200
Date:   Fri Sep 20 08:03:28 2013 +0200
Date:   Fri Sep 20 08:02:05 2013 +0200
Date:   Thu Sep 19 09:53:10 2013 +0200

Wait, that seems strange, doesn't it? If it's supposed to use the last second of the specified date, why would it display a commit that happened at 09:53:10 on that date? Shouldn't git only display the commits that happened after 19.09.2013?

But wait, it gets even stranger! I tried adding a time, which resulted in

git log --since=20-09-201309:00:00 
Date:   Fri Sep 20 08:04:13 2013 +0200
Date:   Fri Sep 20 08:03:28 2013 +0200
Date:   Fri Sep 20 08:02:05 2013 +0200

That did the tri...wait a minute...All the commits happened before 09:00:00. Why does git display them? In fact, as far as I'm aware I just made a syntax error too! Let's try out some stuff:

git log --since=20-09-201312:08:00 | grep Date:
Date:   Fri Sep 20 08:04:13 2013 +0200
Date:   Fri Sep 20 08:03:28 2013 +0200
Date:   Fri Sep 20 08:02:05 2013 +0200

Still works...

git log --since=20-09-201312:09:00 | grep Date:
<nothing>

Hmm, what happened there? Seems like git uses only the last two :-separated numbers. But why would git display the commits that happened after 20.09.2013 08:00 if it seems to think that actually I'm looking for commits after 20.09.201312 08:00? This doesn't make any sense to me.

Can anyone explain this mess to me? It's not that I don't have a solution to solve my problem, but I want to understand, what is happening here...

like image 728
Vince Avatar asked Sep 20 '13 06:09

Vince


1 Answers

By default, the date in git log will show in the default format.

--date=default shows timestamps in the original timezone (either committer’s or author’s).

Based on Git help log

--date=local shows timestamps in user’s local timezone.

--date=default shows timestamps in the original timezone (either committer’s or author’s).

I suggest you run git log --date=local --since=<your date>. It's supposed to show all commits in your local machine's time.

Now, back to your question about --since.

If --since=<date> is without specific a time, it will use your local time at the time you run this command.

For example,

--since "20-09-2013"

when you run this command at 09AM, will act as

--since "20-09-2013 09:00:00"

so, that's why it doesn't make some commits on that day show up. (because it already passed your current time)

if you would like to search for all commits for today then use

--since "20-09-2013 00:00:00"

back to mystery story

So, now git log --since=19-09-2013. That returns

Date: Fri Sep 20 08:04:13 2013 +0200

Date: Fri Sep 20 08:03:28 2013 +0200

Date: Fri Sep 20 08:02:05 2013 +0200

Date: Thu Sep 19 09:53:10 2013 +0200

What I guess that you have run this command from 08:04:13 afterward on 20 Sep 2013. (Based on your hint that when you use since today, it shows nothing.).

like image 78
scalopus Avatar answered Sep 20 '22 13:09

scalopus