1

We use extensively git shortlog --summary --after='2022-01-01 00' --before='2022-12-31' in our end of year reviews and statistics.

$ git shortlog --summary --after='2022-01-01 00' --before='2022-12-31'`
   300  John
    90  Jane
    30  Jack
$ git shortlog --summary --after='2021-01-01 00' --before='2021-12-31'`
   (empty)

Unfortunately the data is wrong.

In 2022 John had zero commits and Jane had around 20 and John and Jack had around 10 commits each in 2021.

We tracked this to the history rewrites that were done in 2022, and that git shortlog --summary uses the commit-date of the commits (which a lot of them now show the year 2022).

Is there a way to make git shortlog --sumary use the commit author-date instead?

We have scoured the git-log and the git-shortlog man pages but no luck...

ateam
  • 137
  • 1
  • 11
  • I think you have this backward. It's the `--before` and `--after` that are selecting based on commit date rather than `shortlog --summary`. – TTT Dec 16 '22 at 20:00
  • Does this answer your question? [How to get git to show commits in a specified date range for author date?](https://stackoverflow.com/questions/37311494/how-to-get-git-to-show-commits-in-a-specified-date-range-for-author-date) – TTT Dec 16 '22 at 20:00
  • I just voted to close, and it is a duplicate if you accept that the answer is you can't. However, if you choose to go the scripting route, the answer to this question may actually be different when applying the script in conjunction with `shortlog --summary`, and if that's the case, perhaps we shouldn't close this. My gut feeling is you just can't though, in which case you'll have to use a separate script to achieve what you want. – TTT Dec 16 '22 at 20:03
  • I'm curious what is the data point you're actually trying to capture? And, what decisions are you intending to make based on the results? There may be a much easier way to get the data you're looking for. – TTT Dec 16 '22 at 20:40
  • 1
    @TTT - yearly "productivity report", dream of *gull-management*. About linked URL - direct URL of [answer](https://stackoverflow.com/a/37311766/960558) may be better (here) – Lazy Badger Dec 16 '22 at 20:47
  • @ttt Yes, it is, in part, productivity report, we like to graph this stuff alongside many other datapoints. – ateam Dec 17 '22 at 03:00

2 Answers2

1

You can try now Git 2.39 with

  • --group option to use any grouping parameters
  • and due to

git shortlog" learned to group by the "format" string

you can have something like (TBT!!!) git shortlog --date='format:%Y' --group='%ad' -s

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • Whoa... What are the chances that the latest version of Git, which was released 4 days ago, makes this finally achievable? – TTT Dec 16 '22 at 22:10
  • I can't tell just by staring at it- is this actually selecting by an author date range? – TTT Dec 16 '22 at 22:13
  • 1
    @TTT - no, it's post-*grouping* of pre-flltered by (unknown date) objects. Year-group for excluding after all wrong %ad commits (pre-2022), maybe have to be paired with grop by author (many groups are allowed, according to announce) – Lazy Badger Dec 16 '22 at 22:21
  • 1
    @TTT - and no, date-related logic seems not changed, AFAICS, but with two groups (hopefully, nested) we just can separate commits with author-date different from commit-date – Lazy Badger Dec 16 '22 at 22:34
0

Thank you @lazy-badger for pointing us to the right direction.

In short, as specified in this answer, there is no commandline argument for it.

But, git(v2.39) has another option we can use.

$ git shortlog --date='format:%Y' --group='format:%ad %aN <%aE>' --summary
   111  2018 John <*>
     2  2018 Jack <*>
   134  2019 John <*>
    22  2019 Jack <*>
    95  2020 John <*>
    13  2020 Jack <*>
     1  2020 Jane <*>
    65  2021 John <*>
    36  2021 Jack <*>
    15  2021 Jane <*>
    24  2022 Jack <*>
    20  2022 Jane <*>
     4  2022 Joel <*>

With %ad being the author date in the specified date format, %aN being the author respecting .mailmap, and %aE being the email respecting .mailmap. (Check git-log man page PRETTY FORMATS section)

So far the data seems correct.

Of course --after and --before are still working on a commit-date dataset, and so, are unusable in our situation.

How to do grouping bounded by dates is still unknown. (How do you even grok a 2000+ lines man page...)

At this point git devs should just make a command that dumps the history as a sqlite3 db so it can be used for data manglement.


Here's an extra requested test.

$ git shortlog --date='format:%Y' --group='format:%ad' --group=author  --summary
   113  2018
   156  2019
   109  2020
   116  2021
    48  2022
   405  John
    97  Jack
    36  Jane
     4  Joel
ateam
  • 137
  • 1
  • 11