git shortlog | Use git shortlog to summarize Git's log output
Table of Contents
- What is Git Shortlog?
- git shortlog Example
- The difference between Git author and Git committer
- Git shortlog summary flags
- Formatting and filtering shortlog options
- Next Steps
In this article, we'll explain how to use the
git shortlog command to create a summary of Git's log output.
What is Git Shortlog?
git shortlog command is a lesser-known git command that was actually introduced back in 2008. Its purpose is to provide a different view of the git log output that is more of a summarized view for use in release announcements and another reporting scenarios.
It can be used to display a count and list of the commits made by authors during a specific time period like a release cycle, and sort this list alphabetically or by number of commits made.
git shortlog Example
By default, running git shortlog displays a summary of commits grouped by author, listing the number of commits made my each other, a one-line version of each commit message, and the authors are sorted in alphabetical order:
$ git shortlog Bob Bobson (3): Initial commit. Add file test.txt Build feature xyz Rob Robson (1): Add .gitignore Will Smithson (2): Add readme Update feature xyz ...
If the output surpasses one terminal screen, it is paged using the configured Git pager, which is
less by default. The spacebar can be used to scroll to the next page and the
b key can be used to scroll back to the previous page.
The difference between Git author and Git committer
Many newer Git users might not know that Git actually records two developer references for each commit - the author and the committer.
The author is permanently set as the person who initially wrote the change and committed it for the first time. Initially, the committer is set to the same value. However, if the commit is applied later as patch by another user as a part of the integration process, the committer information will be updated to reflect the user who performed that action.
Furthermore, Git stores multiple dates for each commit, the Author Date and the Committer Date, which correspond to the author and committer as described above.
The git shortlog command can be used to group commits by committer instead of author, as follows:
$ git shortlog --group=committer
--committer or simply
-c flags can be used as shorthands.
Git shortlog summary flags
Git shortlog has a summary flag "-s" which can produce very interesting and useful information.
The "-s" flag simply produces an even shorter summarized output, showing the number of commits made by each author:
$ git shortlog -s 3 Bob Bobson 1 Rob Robson 2 Will Smithson
Note that the output is still sorted alphabetically by author name.
The "-n" flag can be used to changed the sorting method to sort by number of commits per author instead of author name:
$ git shortlog -sn 1 Rob Robson 2 Will Smithson 3 Bob Bobson
Formatting and filtering shortlog options
One cool thing about Git's shortlog is that it can be combined with pretty much any option you can use with Git log. This includes formatting options such as
--format=<format>, in addition to useful time filters such as
--until which will narrow down commits to those within the specified timerange:
$ git shortlog --format="%s %ae" --since="01-01-2022" --until="01-01-2023"
This version of the command will group commits by author name, display the commits in a oneline format followed by the author email, and will only show commits made between 2022 and 2023.
In this article, we explained how to use the git shortlog command as an alternative form of viewing Git's commit history statistics. We provided several examples of how the shortlog can be used along with its various options and flags.
Definitely give it a try and you might see how slicing and dicing your Git commit history can provide useful insights for your team.
If you're interested in learning more about how Git works under the hood, check out our Baby Git Guidebook for Developers, which dives into Git's code in an accessible way. We wrote it for curious developers to learn how Git works at the code level. To do this, we documented the first version of Git's code and discuss it in detail.
We hope you enjoyed this post! Feel free to shoot me an email at firstname.lastname@example.org with any questions or comments.
Recommended product: Decoding Git Guidebook for Developers