# How to determine the number of unique recent committers on a branch?

6 messages from 2022-03-23 to 2022-03-23. Participants: Sebastian Schuberth, Ævar Arnfjörð Bjarmason, Junio C Hamano.
Thread: https://gitlist.dev/t/57602

## Sebastian Schuberth, 2022-03-23 10:23

Subject: How to determine the number of unique recent committers on a branch?
Message-ID: <CAHGBnuPavzr_gq0ake6bOQETmHBnU2XOWdDz-UtkBP_+rRdYfA@mail.gmail.com>
URL: https://gitlist.dev/e/CAHGBnuPavzr_gq0ake6bOQETmHBnU2XOWdDz-UtkBP_%2BrRdYfA%40mail.gmail.com

```
Hi,

I'm trying to determine the number of unique committers who have
recently committed to a branch. "Recently" should be configurable, but
for my example I'll use a period of 3 months.

At first, I thought the [<refname>]@{<date>} syntax [1] in conjunction
with git "shortlog -s" could be helpful here, like

$ git shortlog -s main@{3.months.ago} | wc -l

But then I realized that just like with the --since option, the <date>
counts relative to the current date, not relative to the date of the
last commit on the given branch. To me, that's rather counterintuitive
for the [<refname>]@{<date>} syntax.

So, what would be a good way to achieve what I want with only
Git-means (and maybe `wc`), but without any awk / Perl scripting
magic?

Thanks in advance!

[1]: http://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltrefnamegtltdategtemegemmasteryesterdayememHEAD5minutesagoem

-- 
Sebastian Schuberth

```

## Ævar Arnfjörð Bjarmason, 2022-03-23 12:30

Subject: Re: How to determine the number of unique recent committers on a branch?
Message-ID: <220323.86o81wonlf.gmgdl@evledraar.gmail.com>
URL: https://gitlist.dev/e/220323.86o81wonlf.gmgdl%40evledraar.gmail.com
In-Reply-To: <CAHGBnuPavzr_gq0ake6bOQETmHBnU2XOWdDz-UtkBP_+rRdYfA@mail.gmail.com>

```

On Wed, Mar 23 2022, Sebastian Schuberth wrote:

> Hi,
>
> I'm trying to determine the number of unique committers who have
> recently committed to a branch. "Recently" should be configurable, but
> for my example I'll use a period of 3 months.
>
> At first, I thought the [<refname>]@{<date>} syntax [1] in conjunction
> with git "shortlog -s" could be helpful here, like
>
> $ git shortlog -s main@{3.months.ago} | wc -l
>
> But then I realized that just like with the --since option, the <date>
> counts relative to the current date, not relative to the date of the
> last commit on the given branch. To me, that's rather counterintuitive
> for the [<refname>]@{<date>} syntax.
>
> So, what would be a good way to achieve what I want with only
> Git-means (and maybe `wc`), but without any awk / Perl scripting
> magic?
>
> Thanks in advance!
>
> [1]: http://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltrefnamegtltdategtemegemmasteryesterdayememHEAD5minutesagoem

The ref@{} syntax will give you ref*log* times, which is probably not
what you want.

I think --since to "rev-list" combined with e.g. "shortlog" is what you
want here, e.g. on git.git:
	
	$ git -P shortlog --since=2.weeks.ago -sn origin/master 
	    36  Junio C Hamano
	    12  Derrick Stolee
	     2  Shubham Mishra
	     1  Michael J Gruber
	     1  Ævar Arnfjörð Bjarmason

Maybe there's a way to get it to spew that out without the numeric
summary, but I can't recall one offhand. I.e. you'd still need awk/cut,
but at least not uniq anymore..

```

## Sebastian Schuberth, 2022-03-23 13:00

Subject: Re: How to determine the number of unique recent committers on a branch?
Message-ID: <CAHGBnuMRKhsF-xCL944KD5GFPWYe-9cSp6FBZfaZ7bdVTkgjng@mail.gmail.com>
URL: https://gitlist.dev/e/CAHGBnuMRKhsF-xCL944KD5GFPWYe-9cSp6FBZfaZ7bdVTkgjng%40mail.gmail.com
In-Reply-To: <220323.86o81wonlf.gmgdl@evledraar.gmail.com>

```
On Wed, Mar 23, 2022 at 1:33 PM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:

> I think --since to "rev-list" combined with e.g. "shortlog" is what you
> want here, e.g. on git.git:
>
>         $ git -P shortlog --since=2.weeks.ago -sn origin/master

But that still interprets "2.weeks.ago" relative to today, right? So,
for a repo to which no one committed to in the last 2 weeks, it would
show nothing. But what I'd like to get is the number of committers
since 2 weeks before the latest commit. Any idea how to get that
easily?

-- 
Sebastian Schuberth

```

## Ævar Arnfjörð Bjarmason, 2022-03-23 14:47

Subject: Re: How to determine the number of unique recent committers on a branch?
Message-ID: <220323.86bkxwogxs.gmgdl@evledraar.gmail.com>
URL: https://gitlist.dev/e/220323.86bkxwogxs.gmgdl%40evledraar.gmail.com
In-Reply-To: <CAHGBnuMRKhsF-xCL944KD5GFPWYe-9cSp6FBZfaZ7bdVTkgjng@mail.gmail.com>

```

On Wed, Mar 23 2022, Sebastian Schuberth wrote:

> On Wed, Mar 23, 2022 at 1:33 PM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>
>> I think --since to "rev-list" combined with e.g. "shortlog" is what you
>> want here, e.g. on git.git:
>>
>>         $ git -P shortlog --since=2.weeks.ago -sn origin/master
>
> But that still interprets "2.weeks.ago" relative to today, right? So,
> for a repo to which no one committed to in the last 2 weeks, it would
> show nothing. But what I'd like to get is the number of committers
> since 2 weeks before the latest commit. Any idea how to get that
> easily?

Ah, sorry. I managed to (mis)read your question.

Perhaps there's a way to do that in one command, but I don't think so,
but I may be wrong.

But you *can* do by grabbing the epoch from the tip commit and doing
some basic shell-math on it:

    git log --since=$(($(git log --oneline -1 --date=unix --pretty=format:%ad origin/master) - $((60*60*24*7*2)) )) origin/master

It would be nice if we had some option to to do that, e.g.:

    git log --since=2.weeks.ago --date-now=February.2018

Or To get you things in late January 2018. Or even:

    git -c core.time="February.2018" log --since=2.weeks.ago

To fool the entirety of git to use a given time() as current (but of
course it would also need to "adjust back" commit dates for relative
--since).

I'm 99% sure we don't have that, especially from looking at some of the
code just now. But in the meantime you can hack it as above.

```

## Junio C Hamano, 2022-03-23 20:48

Subject: Re: How to determine the number of unique recent committers on a branch?
Message-ID: <xmqqy210qttf.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqy210qttf.fsf%40gitster.g
In-Reply-To: <CAHGBnuPavzr_gq0ake6bOQETmHBnU2XOWdDz-UtkBP_+rRdYfA@mail.gmail.com>

```
Sebastian Schuberth <sschuberth@gmail.com> writes:

> I'm trying to determine the number of unique committers who have
> recently committed to a branch. "Recently" should be configurable, but
> for my example I'll use a period of 3 months.
>
> At first, I thought the [<refname>]@{<date>} syntax [1] in conjunction
> with git "shortlog -s" could be helpful here, like
>
> $ git shortlog -s main@{3.months.ago} | wc -l

As reflog is pretty much the local matter, this is "find out the
commit _I_ happened to have seen at the tip of 'main' in _this_
repository 3 months ago, and count all commits before that one".

If you were taking 6 months sabbatical, not fetching the repository
during that time, and then you fetched to become up to date with the
upstream, you may have had a copy of the shared project history only
as of 6 months ago with that notation, even though the syntax is
asking for "3 months ago", simply because that was the commit your
repository had 3 months ago at the tip of the branch.

    $ git log --until=3.months.ago

would instead look at the timestamp recorded in commit objects,
which would probably be more relevant to project participants.

```

## Sebastian Schuberth, 2022-03-23 22:14

Subject: Re: How to determine the number of unique recent committers on a branch?
Message-ID: <CAHGBnuMjRNiHr+V7Vc6N72CFbtVDmTapf3w1vn=1TOPB89W0ag@mail.gmail.com>
URL: https://gitlist.dev/e/CAHGBnuMjRNiHr%2BV7Vc6N72CFbtVDmTapf3w1vn%3D1TOPB89W0ag%40mail.gmail.com
In-Reply-To: <220323.86bkxwogxs.gmgdl@evledraar.gmail.com>

```
On Wed, Mar 23, 2022 at 3:57 PM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:

> But you *can* do by grabbing the epoch from the tip commit and doing
> some basic shell-math on it:
>
>     git log --since=$(($(git log --oneline -1 --date=unix --pretty=format:%ad origin/master) - $((60*60*24*7*2)) )) origin/master

Thanks, that works!

However, as --since works on the commit date, shouldn't it also be %cd
instead of %ad in the format string for consistency?

-- 
Sebastian Schuberth

```
