threads / discuss / 64195

0-Based indexes for git log

Subject: 0-Based indexes for git log

## tl;dr

17 messages between Sep 23, 2025 and Sep 25, 2025.

replies: 16people: 7as markdown or json

π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣· Sep 23, 2025, 21:15 UTC Β· lore

In git log it uses a 1-based index for the date instead of a 0 based index. So it says "Fri Sep 19 14:23:24 2025 -0400" when it should say "Fri Sep 18 14:23:24 2025 -0400" (or "Friday 2025-8-18Β 14:23:24 (-4:00.00)"Β  to get a better format)

-- 
George truly, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣
This email does not constitute a legally binding contract
Ben KnobleΒ· Sep 24, 2025, 02:12 UTC Β· re: π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 Β· lore

Re: 0-Based indexes for git log

> Le 23 sept. 2025 Γ  17:16, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 <velocifyer@velocifyer.com> a Γ©crit :
> 
> ο»ΏIn git log it uses a 1-based index for the date instead of a 0 based index. So it says "Fri Sep 19 14:23:24 2025 -0400" when it should say "Fri Sep 18 14:23:24 2025 -0400" (or "Friday 2025-8-18 14:23:24 (-4:00.00)"  to get a better format)
Are these date formats locale-specific? In both the US English and France French locales I use commonly, the 19th of September in 2025 _is_ a Friday. Showing 18 would only be confusing.
π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣· Sep 24, 2025, 13:46 UTC Β· re: Ben Knoble Β· lore

Re: 0-Based indexes for git log

> Are these date formats locale-specific? In both the US English and France French locales I use commonly, the 19th of September in 2025 _is_ a Friday. Showing 18 would only be confusing.

Showing 19 confuses me because i'm used to 0-based indexes where the 19th is labeld as 18. Showing 18 would not cunfuse most people.

-- 
George truly, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣
This email does not constitute a legally binding contract
Remember to reply all on mailing lists (this is here so i don't forget 
to use reply all)(If you are reading this i forgot to remove it)
Ben KnobleΒ· Sep 24, 2025, 15:26 UTC Β· re: π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 Β· lore

Re: 0-Based indexes for git log

Show 7 quoted lines
> Le 24 sept. 2025 Γ  09:46, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 <velocifyer@velocifyer.com> a Γ©crit :
> 
> ο»Ώ
>> 
>> Are these date formats locale-specific? In both the US English and France French locales I use commonly, the 19th of September in 2025 _is_ a Friday. Showing 18 would only be confusing.
> 
> Showing 19 confuses me because i'm used to 0-based indexes where the 19th is labeld as 18. Showing 18 would not cunfuse most people.
I would need evidence of that. Everyone I interact with agrees to write Β« 19 Β» when Β« 19th Β» is implied.
As I asked: is this particular to an community? I’m genuinely curious if there are groups or cultures that communicate this way. 
As Peff points out, you can probably make commands display your own personal preference (or a locale should handle this for your community). But I don’t think this is something we can force on other people, because it would be confusing. 
Jeff KingΒ· Sep 24, 2025, 05:22 UTC Β· re: π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 Β· lore

Re: 0-Based indexes for git log

On Tue, Sep 23, 2025 at 05:15:46PM -0400, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 wrote:
> In git log it uses a 1-based index for the date instead of a 0 based index.
> So it says "Fri Sep 19 14:23:24 2025 -0400" when it should say "Fri Sep 18
> 14:23:24 2025 -0400"

Are you proposing that the first day of September is the 0th? You might be able to do that with locale support and using strftime's %c option, but I'm not sure how powerful locales are (or how one even defines them).

> (or "Friday 2025-8-18Β 14:23:24 (-4:00.00)"Β  to get a
> better format)

If you just care about the format, check out the --date option in git-log's manpage. Especially the "format:" specifier, which relies on strftime, like:

  git log --date=format:'%A %Y-%m-%d %H:%M:%S (%z)'
-Peff
π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣· Sep 24, 2025, 13:42 UTC Β· re: Jeff King Β· lore

Re: 0-Based indexes for git log

[sent again because i didn`t reply all
> Are you proposing that the first day of September is the 0th? You might
> be able to do that with locale support and using strftime's %c option,
> but I'm not sure how powerful locales are (or how one even defines
> them).
No, i am sugesting that it is still the 1st but it is september 0
-- 
George truly, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣
This email does not constitute a legally binding contract
Remember to reply all on mailing lists (this is here so i don't forget 
to use reply all)(If you are reading this i forgot to remove it)
Nico WilliamsΒ· Sep 24, 2025, 15:43 UTC Β· re: π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 Β· lore

Re: 0-Based indexes for git log

On Tue, Sep 23, 2025 at 05:15:46PM -0400, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 wrote:
> In git log it uses a 1-based index for the date instead of a 0 based index.
> So it says "Fri Sep 19 14:23:24 2025 -0400" when it should say "Fri Sep 18
> 14:23:24 2025 -0400" (or "Friday 2025-8-18Β 14:23:24 (-4:00.00)"Β  to get a
> better format)
Day of month numbers are 1-based.
Junio C HamanoΒ· Sep 24, 2025, 16:53 UTC Β· re: Nico Williams Β· lore

Re: 0-Based indexes for git log

Nico Williams <nico@cryptonector.com> writes:
Show 7 quoted lines
> On Tue, Sep 23, 2025 at 05:15:46PM -0400, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 wrote:
>> In git log it uses a 1-based index for the date instead of a 0 based index.
>> So it says "Fri Sep 19 14:23:24 2025 -0400" when it should say "Fri Sep 18
>> 14:23:24 2025 -0400" (or "Friday 2025-8-18Β 14:23:24 (-4:00.00)"Β  to get a
>> better format)
>
> Day of month numbers are 1-based.
Correct.
There are a few things in Git that are 0 based, but not so many.
 * parent numbers are 1-based.  HEAD~1 is the "previous commit", aka
   "first parent".  HEAD~0 is the HEAD itself.
 * merge parent numbers are 2-based (sanity of this statement is
   already questionable).  If HEAD is a merge, HEAD~2 is the
   "(first) side branch that was merged", HEAD~3 is the "(second)
   side brnach that was merged (in an octopus merge), and so on.
 * reflog entries are 1-based.  @{1} is the "previous object pointed
   by the current branch", @{2} is one before that.  @{0} is the
   current branch itself.
 * stash entries are counted 0-based.  "git stash list" shows from
   stash@{0} that is the most recently created stash entry.
π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣· Sep 24, 2025, 17:11 UTC Β· re: Junio C Hamano Β· lore

Re: 0-Based indexes for git log

>> Day of month numbers are 1-based.
> Correct.
No, day of month numbers are 0-based.
> There are a few things in Git that are 0 based, but not so many.
>
>   * parent numbers are 1-based.  HEAD~1 is the "previous commit", aka
>     "first parent".  HEAD~0 is the HEAD itself.
HEAD~1 just means HEAD - 1 commit.(AKA "reverse 0-based index")
>   * reflog entries are 1-based.  @{1} is the "previous object pointed
>     by the current branch", @{2} is one before that.  @{0} is the
>     current branch itself.
No, that is just a reverse 0-based index.
>   * stash entries are counted 0-based.  "git stash list" shows from
>     stash@{0} that is the most recently created stash entry.
That is correct. It's a reverse 0-based index becuase it uses reflog syntax.
-- 
George truly, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣
This email does not constitute a legally binding contract
Ben KnobleΒ· Sep 24, 2025, 17:28 UTC Β· re: Junio C Hamano Β· lore

Re: 0-Based indexes for git log

Show 23 quoted lines
> Le 24 sept. 2025 Γ  12:53, Junio C Hamano <gitster@pobox.com> a Γ©crit :
> 
> ο»ΏNico Williams <nico@cryptonector.com> writes:
> 
>>> On Tue, Sep 23, 2025 at 05:15:46PM -0400, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 wrote:
>>> In git log it uses a 1-based index for the date instead of a 0 based index.
>>> So it says "Fri Sep 19 14:23:24 2025 -0400" when it should say "Fri Sep 18
>>> 14:23:24 2025 -0400" (or "Friday 2025-8-18 14:23:24 (-4:00.00)"  to get a
>>> better format)
>> 
>> Day of month numbers are 1-based.
> 
> Correct.
> 
> There are a few things in Git that are 0 based, but not so many.
> 
> * parent numbers are 1-based.  HEAD~1 is the "previous commit", aka
>   "first parent".  HEAD~0 is the HEAD itself.
> 
> * merge parent numbers are 2-based (sanity of this statement is
>   already questionable).  If HEAD is a merge, HEAD~2 is the
>   "(first) side branch that was merged", HEAD~3 is the "(second)
>   side brnach that was merged (in an octopus merge), and so on.
HEAD^2, 3, etc., rather? :)
Patrick SteinhardtΒ· Sep 25, 2025, 05:46 UTC Β· re: Ben Knoble Β· lore

Re: 0-Based indexes for git log

On Wed, Sep 24, 2025 at 01:28:31PM -0400, Ben Knoble wrote:
Show 6 quoted lines
> > * merge parent numbers are 2-based (sanity of this statement is
> >   already questionable).  If HEAD is a merge, HEAD~2 is the
> >   "(first) side branch that was merged", HEAD~3 is the "(second)
> >   side brnach that was merged (in an octopus merge), and so on.
> 
> HEAD^2, 3, etc., rather? :)

Probably. I also always regarded this as the nth parent, not the nth merge parent. HEAD^1 returns the first parent even for non-merges, HEAD^2 the second and so on. So I'd claim these are also 1-based.

Patrick
Junio C HamanoΒ· Sep 25, 2025, 13:25 UTC Β· re: Ben Knoble Β· lore

Re: 0-Based indexes for git log

Ben Knoble <ben.knoble@gmail.com> writes:
Show 6 quoted lines
>> * merge parent numbers are 2-based (sanity of this statement is
>>   already questionable).  If HEAD is a merge, HEAD~2 is the
>>   "(first) side branch that was merged", HEAD~3 is the "(second)
>>   side brnach that was merged (in an octopus merge), and so on.
>
> HEAD^2, 3, etc., rather? :)

Thanks for correcting me. Yes. And HEAD^1 is the first parent that is the same as HEAD~1.

Nico WilliamsΒ· Sep 24, 2025, 17:04 UTC Β· re: π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 Β· lore

Re: 0-Based indexes for git log

On Wed, Sep 24, 2025 at 01:01:30PM -0400, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 wrote:
> > Day of month numbers are 1-based.
> 
> I consider day of month to use a 0-based index

The rest of the world does not. You want to be able to interoperate with the rest of the world. So day of month numbers are 1-based. I also wish everything were 0-based, but it's not. That's just life.

π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣· Sep 24, 2025, 17:15 UTC Β· re: π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 Β· lore

Re: 0-Based indexes for git log

Show 5 quoted lines
> In git log it uses a 1-based index for the date instead of a 0 based 
> index. So it says "Fri Sep 19 14:23:24 2025 -0400" when it should say 
> "Fri Sep 18 14:23:24 2025 -0400" (or "Friday 2025-8-18Β 14:23:24 
> (-4:00.00)"Β  to get a better format)
>

I suggest git adds a config option for 0-based date and automaticly uses 0-based date if there is a file at $HOME/use-0-based-index-for-date or $USE-0-BASED-INDEX-FOR-DATE == true

-- 
George truly, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣
This email does not constitute a legally binding contract
Emily ShafferΒ· Sep 24, 2025, 17:22 UTC Β· re: π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 Β· lore

Re: 0-Based indexes for git log

On Wed, Sep 24, 2025 at 10:15β€―AM π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 <velocifyer@velocifyer.com> wrote:

Show 9 quoted lines
>
> > In git log it uses a 1-based index for the date instead of a 0 based
> > index. So it says "Fri Sep 19 14:23:24 2025 -0400" when it should say
> > "Fri Sep 18 14:23:24 2025 -0400" (or "Friday 2025-8-18 14:23:24
> > (-4:00.00)"  to get a better format)
> >
> I suggest git adds a config option for 0-based date and automaticly uses
> 0-based date if there is a file at $HOME/use-0-based-index-for-date or
> $USE-0-BASED-INDEX-FOR-DATE == true

Git uses strftime from libc for date formatting. strftime[1] doesn't offer a way to format the date as you prefer - what you're asking for appears to be a personal preference, not a standard in any community of the world. I think that your best bet would be to attempt to contribute an option to strftime to render the day of the month from 0-30, but I would be surprised if such a contribution were to be welcomed - as, again, this looks like a preference held by very few. Based on my quick refresher through date.[ch] in the Git codebase, it would be infeasible to add such a flag and custom formatting.

However, Git is open source software, and you're fully welcome to patch your copy of Git to accept such a config (or this ~/some-file, which is not a way Git typically sets configuration) and build it yourself locally.

1: https://www.man7.org/linux/man-pages/man3/strftime.3.html
>
> --
> George truly, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣
> This email does not constitute a legally binding contract
π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣· Sep 24, 2025, 17:18 UTC Β· re: π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣 Β· lore

Re: 0-Based indexes for git log

[resending because i made a typo]
Show 5 quoted lines
> In git log it uses a 1-based index for the date instead of a 0 based 
> index. So it says "Fri Sep 19 14:23:24 2025 -0400" when it should say 
> "Fri Sep 18 14:23:24 2025 -0400" (or "Friday 2025-8-18Β 14:23:24 
> (-4:00.00)"Β  to get a better format)
>

I suggest git adds a config option for 0-based date and automatically uses 0-based date if there is a file at $HOME/.config/use-0-based-index-for-date or $USE-0-BASED-INDEX-FOR-DATE == true

-- 
George truly, π•π•–π•π• π•”π•šπ•—π•ͺ𝕖𝕣
This email does not constitute a legally binding contract

← back to recent threads