Table of Contents
introduction
In this article we will explain how to use git shortlog
The command to generate a summary of the Git log output.
What is Git Shortlog?
God 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 git log output that is more of a summarized view for use in release announcements and other reporting scenarios.
It can be used to display a count and list of commits made by authors during a certain time period such as a release cycle, and sort this list alphabetically or by the number of commits made.
git shortlog example
By default, running git shortlog displays a summary of commits grouped by author, with a list of the number of commits made to each other, a one-line version of each commit message, and authors sorted alphabetically:
$ 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 exceeds one terminal screen, it is forwarded using the configured Git pager, ie less
By default. You can use the spacebar to scroll to the next page and b
You can use the key to scroll back to the previous page.
The difference between a Git author and a Git committer
Many newer Git users may not know that Git actually registers two developer references for each commit – the author And the undertakes.
The author is permanently defined as the person who initially wrote the change and committed it the first time. Initially, the committer is set to the same value. However, if the commit is later applied as a fix by another user as part of the integration process, commit information will be updated to reflect the user who performed that action.
Furthermore, Git stores multiple dates for each commit, e.g Author’s date And the A date is requiredwhich match the author and the author as described above.
You can use the git shortlog command to group commits by committer instead of author, as follows:
$ git shortlog --group=committer
Alternatively, the --committer
or simply -c
Flags can be used as shortcuts.
Flags for a brief summary of Git
Git shortlog has a summary flag “-s” which can produce very interesting and useful information.
The “-s” flag simply produces an even shorter summary 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 change 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
Options for designing and filtering a short log
One cool thing about Git shortlog is that it can be combined with almost any option you can use with Git log. This includes design options such as --format=<format>
In addition to useful time filters such as --since
and --until
which will reduce the liabilities to those within the specified time frame:
$ git shortlog --format="%s %ae" --since="01-01-2022" --until="01-01-2023"
This version of the command will group pledges by author name, display the pledges in oneline format followed by the author’s email, and only display pledges made between 2022 and 2023.
Summary
In this article, we explained how to use the git shortlog command as an alternative way to view Git commit history statistics. We have provided several examples of how 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 commit history in Git can provide useful insights to your team.
next steps
If you’re interested in learning more about how Git works under the hood, check out our Baby Git guide for developers, which dives into the Git code in an accessible way. We wrote it for developers who are curious to learn how Git works at the code level. To that end, we’ve documented the first version of Git’s code and discussed it in detail.
We hope you enjoyed this post! Feel free to email me at jacob@initialcommit.io with any questions or comments.