git shortlog
by itself does not address the original question of total number of commits (not grouped by author)
That is true, and git rev-list HEAD --count remains the simplest answer.
However, with Git 2.29 (Q4 2020), "git shortlog
"(man) has become more precise.
It has been taught to group commits by the contents of the trailer lines, like "Reviewed-by:
", "Coauthored-by:
", etc.
See commit 63d24fa, commit 56d5dde, commit 87abb96, commit f17b0b9, commit 47beb37, commit f0939a0, commit 92338c4 (27 Sep 2020), and commit 45d93eb (25 Sep 2020) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
-- in commit 2fa8aac, 04 Oct 2020)
shortlog
: allow multiple groups to be specified
Signed-off-by: Jeff King
Now that shortlog
supports reading from trailers, it can be useful to combine counts from multiple trailers, or between trailers and authors.
This can be done manually by post-processing the output from multiple runs, but it's non-trivial to make sure that each name/commit pair is counted only once.
This patch teaches shortlog to accept multiple --group
options on the command line, and pull data from all of them.
That makes it possible to run:
git shortlog -ns --group=author --group=trailer:co-authored-by
to get a shortlog that counts authors and co-authors equally.
The implementation is mostly straightforward. The "group
" enum becomes a bitfield, and the trailer key becomes a list.
I didn't bother implementing the multi-group semantics for reading from stdin. It would be possible to do, but the existing matching code makes it awkward, and I doubt anybody cares.
The duplicate suppression we used for trailers now covers authors and committers as well (though in non-trailer single-group mode we can skip the hash insertion and lookup, since we only see one value per commit).
There is one subtlety: we now care about the case when no group bit is set (in which case we default to showing the author).
The caller in builtin/log.c
needs to be adapted to ask explicitly for authors, rather than relying on shortlog_init()
. It would be possible with some gymnastics to make this keep working as-is, but it's not worth it for a single caller.
git shortlog
now includes in its man page:
--group=<type>
Group commits based on <type>
. If no --group
option is
specified, the default is author
. <type>
is one of:
author
, commits are grouped by author
committer
, commits are grouped by committer (the same as -c
)
This is an alias for --group=committer
.
git shortlog
now also includes in its man page:
If --group
is specified multiple times, commits are counted under each
value (but again, only once per unique value in that commit). For
example, git shortlog --group=author --group=trailer:co-authored-by
counts both authors and co-authors.
git rev-list HEAD --count
git rev-list – Entire