0
0
GitHow-ToBeginner · 3 min read

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:

  • options modify the output format (e.g., -s for summary, -n to sort by number of commits).
  • commit-range specifies 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 -5
Output
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 shortlog with git log which shows detailed commit info.
  • Expecting detailed commit diffs; git shortlog only summarizes commits.
bash
Wrong: git shortlog --oneline
Right: git shortlog -n -s
📊

Quick Reference

OptionDescription
-sShow only commit counts, no messages
-nSort output by number of commits
-eShow author email
-wWrap 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.