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>...]
Basic Example
To see a summary of all commits grouped by author:
git shortlog
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
Filter by Revision Range
To see contributions between two commits (e.g., v1.0
and v2.0
):
git shortlog v1.0..v2.0
Sort by Number of Commits
Use -n
(or --numbered
) to sort authors by commit count:
git shortlog -n
Show Only Commit Counts
Use -s
(or --summary
) to display only commit counts:
git shortlog -s
Output:
10 John Doe
5 Jane Smith
2 Alex Brown
Combine with -e
to Show Emails
To include email addresses:
git shortlog -e
Output:
John Doe <john@example.com> (5):
Fix login page styling
...
Common Use Cases
1. Generating Release Notes
Summarize changes since the last release:
git shortlog v2.0..HEAD
Output:
John Doe (3):
Add dark mode support
Fix mobile responsiveness
Update dependencies
Jane Smith (1):
Patch security vulnerability
2. Tracking Team Contributions
Check contributions in a specific directory (e.g., src/
):
git shortlog -n -- src/
3. Finding Top Contributors
List authors sorted by most commits:
git shortlog -sn
Output:
42 John Doe
31 Jane Smith
15 Alex Brown
4. Checking External Contributions
View commits from a specific author:
git shortlog --author="Jane Smith"
Tips and Tricks
1. Exclude Merge Commits
Use --no-merges
to filter out merge commits:
git shortlog -sn --no-merges
2. Group by Email Instead of Name
Sometimes contributors use different names but the same email. Group by email with:
git shortlog -e -s
3. Limit Output to Top N Contributors
Combine with head
to see only the top 5 contributors:
git shortlog -sn | head -5
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
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
Hey authors! Here’s something exciting: We're offering your special Dev.to drop for our top content creators. Click here here (instant distribution). – Dev.to Community Support