How to Use git shortlog: Syntax, Examples, and Tips
Use
git shortlog to view a summary of commits grouped by author. It shows the number of commits and their messages, helping you understand contribution history quickly. Run git shortlog in your repository to see this summary.Syntax
The basic syntax of git shortlog is:
git shortlog [options] [commit-range]
Here:
optionsmodify the output format (e.g.,-sfor summary,-nto sort by number of commits).commit-rangespecifies which commits to include (default is all commits in current branch).
bash
git shortlog [options] [commit-range]Example
This example shows how to use git shortlog to list commit counts and messages grouped by author for the last 5 commits:
bash
git shortlog -n -s -5Output
3 Alice
2 Bob
Common Pitfalls
Common mistakes when using git shortlog include:
- Not specifying a commit range and getting too much output.
- Confusing
git shortlogwithgit logwhich shows detailed commit info. - Expecting detailed commit diffs;
git shortlogonly summarizes commits.
bash
Wrong: git shortlog --oneline Right: git shortlog -n -s
Quick Reference
| Option | Description |
|---|---|
| -s | Show only commit counts, no messages |
| -n | Sort output by number of commits |
| -e | Show author email |
| -w | Wrap commit messages |
| Specify commits to include (e.g., HEAD~10..HEAD) |
Key Takeaways
Use git shortlog to get a quick summary of commits grouped by author.
Add -n and -s options to sort by commit count and show only counts.
Specify a commit range to limit the summary to recent commits.
git shortlog summarizes commits; it does not show detailed diffs.
Common mistake: confusing git shortlog with git log for detailed info.