DEV Community

Cover image for Day 23/30 - Git Shortlog: Summarize Commit Contributions by Author
Ruqaiya Beguwala
Ruqaiya Beguwala

Posted on • Originally published at Medium

Day 23/30 - Git Shortlog: Summarize Commit Contributions by Author

Introduction

When working with Git, tracking contributions from different authors is essential for understanding project history and collaboration. git shortlog is a powerful command that summarizes commit contributions by author, making it easy to see who contributed what.

Whether you're managing an open-source project, reviewing team contributions, or generating release notes, git shortlog provides a clean, organized way to view commit statistics.


How to Use git shortlog

The basic syntax of git shortlog is:

git shortlog [options] [<revision range>] [--] [<path>...] 
Enter fullscreen mode Exit fullscreen mode

Basic Example

To see a summary of all commits grouped by author:

git shortlog 
Enter fullscreen mode Exit fullscreen mode

Sample Output:

John Doe (5): Fix login page styling Update README.md Refactor user authentication Jane Smith (3): Add API documentation Fix bug in payment processing 
Enter fullscreen mode Exit fullscreen mode

Filter by Revision Range

To see contributions between two commits (e.g., v1.0 and v2.0):

git shortlog v1.0..v2.0 
Enter fullscreen mode Exit fullscreen mode

Sort by Number of Commits

Use -n (or --numbered) to sort authors by commit count:

git shortlog -n 
Enter fullscreen mode Exit fullscreen mode

Show Only Commit Counts

Use -s (or --summary) to display only commit counts:

git shortlog -s 
Enter fullscreen mode Exit fullscreen mode

Output:

 10 John Doe 5 Jane Smith 2 Alex Brown 
Enter fullscreen mode Exit fullscreen mode
Combine with -e to Show Emails

To include email addresses:

git shortlog -e 
Enter fullscreen mode Exit fullscreen mode

Output:

John Doe <john@example.com> (5): Fix login page styling ... 
Enter fullscreen mode Exit fullscreen mode

Common Use Cases

1. Generating Release Notes

Summarize changes since the last release:

git shortlog v2.0..HEAD 
Enter fullscreen mode Exit fullscreen mode

Output:

John Doe (3): Add dark mode support Fix mobile responsiveness Update dependencies Jane Smith (1): Patch security vulnerability 
Enter fullscreen mode Exit fullscreen mode

2. Tracking Team Contributions

Check contributions in a specific directory (e.g., src/):

git shortlog -n -- src/ 
Enter fullscreen mode Exit fullscreen mode

3. Finding Top Contributors

List authors sorted by most commits:

git shortlog -sn 
Enter fullscreen mode Exit fullscreen mode

Output:

 42 John Doe 31 Jane Smith 15 Alex Brown 
Enter fullscreen mode Exit fullscreen mode

4. Checking External Contributions

View commits from a specific author:

git shortlog --author="Jane Smith" 
Enter fullscreen mode Exit fullscreen mode

Tips and Tricks

1. Exclude Merge Commits

Use --no-merges to filter out merge commits:

git shortlog -sn --no-merges 
Enter fullscreen mode Exit fullscreen mode

2. Group by Email Instead of Name

Sometimes contributors use different names but the same email. Group by email with:

git shortlog -e -s 
Enter fullscreen mode Exit fullscreen mode

3. Limit Output to Top N Contributors

Combine with head to see only the top 5 contributors:

git shortlog -sn | head -5 
Enter fullscreen mode Exit fullscreen mode

4. Use with git log for Detailed Reports

Get a summary and then drill into details:

git shortlog -sn git log --author="John Doe" --oneline 
Enter fullscreen mode Exit fullscreen mode

Conclusion

git shortlog is a versatile tool for summarizing commit contributions, making it invaluable for project maintainers, team leads, and developers. Whether you're generating reports, tracking work, or preparing release notes, this command helps you quickly understand contributions in a Git repository.

Try integrating git shortlog into your workflow—whether for code reviews, sprint retrospectives, or open-source maintenance—and see how it improves visibility into your project’s history!

Further Reading:

Would you like a custom script to automate git shortlog reports? Let us know in the comments! 🚀


Up Next in the Series: git diff --word-diff – See word-level changes, not just lines


Daily advance GIT tips in your inbox---worth starting? Respond to my poll here🚀

For more useful and innovative tips and tricks, Let's connect on Medium

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.