Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git log --since date string parsing

Tags:

git

I was looking through some logs in a submodule today (somewhat furiously) and typed some errors into the dates in the command

git log --since="2019-12-31" --oneline | wc -l
      90

and instead of typing that I typed,

git log --since="2019-12=31" --oneline | wc -l
    2147

I was alarmed by the difference is count which is why I was able to notice the error immediately. However, I'm unclear as to what the behavior is in this case. Is this a bug or is this expected behavior for git log?

I would expect an error in parsing but it looks like the logs go back to January or February of 2019.

like image 707
Lucas Roberts Avatar asked Mar 29 '26 01:03

Lucas Roberts


1 Answers

It appears that Git's date parsing just stops when it gets to a part it can't understand. For example "2015-13" is understood as "2015", as is "2015-4444".

In your case, it's treating "2019-12=31" as "2019". And then a second weird "feature" kicks in: --since 2019 does not mean --since 2019-01-01, it means "since today's date in 2019". So the meaning of your --since 2019-12-31 will actually change throughout each year when you run it!

What seems to be happening is:

  1. Generate the current date-time (in your time zone).
  2. Replace the parts you specified in --since, ignoring the month and day part if the parser cannot decide how to parse it.

Note that even the simple and "obviously correct" git log --since 2019-12-31 does not really do what one might expect, because it shows commits since the current time on that day, not since midnight. So unless you specify a full date-time string, there will always be some dependency on the time when the command is executed.

like image 54
John Zwinck Avatar answered Mar 31 '26 03:03

John Zwinck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!