How to fix fatal: no commits to shortlog in Git

GitBEGINNERLOWUpdated Dec 2, 2025ยท 129 views

Git shortlog returns empty output when run in non-interactive environments like scripts, CI systems, or when no revision is specified. This occurs because shortlog expects either a terminal or explicit revision argument.

Quick fix

Fixes fatal: no commits to shortlog

git log --oneline
  1. Verify the issue by checking if you can see commits
  2. Add explicit HEAD reference to git shortlog
  3. Specify a revision range for more control
  4. Pipe git log output to git shortlog
git โ€” error
git log --oneline
fatal: no commits to shortlog

What this error means

The "git shortlog no output" error occurs when git shortlog is invoked without proper context or arguments. Git shortlog is designed to summarize git log output, grouping commits by author. However, it has specific behavior that causes it to produce no output in certain scenarios. According to the official Git documentation, "if no revisions are passed on the command line and either standard input is not a terminal or there is no current branch, git shortlog will output a summary of the log read from standard input, without reference to the current repository." This means when you run git shortlog in automated environments (cron jobs, CI pipelines, pre-commit hooks) or non-interactive shells, it waits for input from stdin rather than defaulting to the repository's history. This is not technically an error in most cases, but rather unexpected behavior that results from how git shortlog determines its data source. When run interactively in a terminal with a current branch, it defaults to HEAD, but this automatic behavior doesn't apply in non-interactive contexts.

Typical symptoms

  • git shortlog command produces no output when run from scripts
  • Empty results from git shortlog in Jenkins, GitLab CI, or other CI systems
  • git shortlog works in terminal but fails in cron jobs or automated tasks
  • Command hangs or returns immediately with no output in pre-commit hooks
  • git shortlog succeeds with git log but fails alone
  • Works interactively but not when called from Emacs shell-command or similar tools

Common causes

  1. Running git shortlog without arguments in a non-interactive shell or script
  2. Executing git shortlog during git hooks when the repository is in a semi-detached state
  3. No current branch available when git shortlog is invoked
  4. stdin is not a terminal and no revision range is specified
  5. Running in CI/CD pipeline without explicitly providing a revision reference
  6. Repository is in a bare state or detached HEAD without explicit revision argument

How to fix "fatal: no commits to shortlog"

1Verify the issue by checking if you can see commits

First, confirm that your repository has commits and that git log works properly:

bash
git log --oneline

If this shows commits, the repository is fine and the issue is with how shortlog is being invoked. If this also shows nothing, you may have a different issue (empty repository, detached state, etc.).

2Add explicit HEAD reference to git shortlog

The simplest fix is to explicitly tell git shortlog which revision to summarize. Use HEAD to get the entire history leading to the current commit:

bash
git shortlog HEAD

For summary format with commit counts:

bash
git shortlog -sn HEAD

For email addresses with counts:

bash
git shortlog -sne HEAD

This works in all contexts: scripts, hooks, CI systems, and interactive terminals.

3Specify a revision range for more control

If you need commits from a specific range, provide explicit start and end points:

bash
# All commits between two tags
git shortlog v1.0..v2.0

# Commits in current branch since main
git shortlog main..HEAD

# Commits in the last 30 days
git shortlog --since="30 days ago"

# All commits reachable from a specific branch
git shortlog origin/main

This is particularly useful in CI environments where you want release notes or specific branch statistics.

4Pipe git log output to git shortlog

The official alternative approach is to pipe git log output to shortlog:

bash
git log --pretty=short | git shortlog

With additional formatting options:

bash
# Summary by author with counts
git log --pretty=short | git shortlog -sn

# Include email addresses
git log --pretty=short | git shortlog -sne

This method explicitly provides the input shortlog needs, working around the terminal detection issue.

5Update scripts and CI configurations

If you have existing scripts or CI jobs failing, update them to include explicit revisions:

Before (fails in CI):

bash
#!/bin/bash
git shortlog -sn

After (works everywhere):

bash
#!/bin/bash
git shortlog -sn HEAD

For Jenkins, GitLab CI, GitHub Actions, or similar:

yaml
# Example GitLab CI
generate_stats:
  script:
    - git shortlog -sne HEAD > contributors.txt
    - git shortlog -sn --since="1 month ago" HEAD > monthly_stats.txt

Advanced notes

Why this behavior exists: Git shortlog's dual-mode behavior (reading from stdin vs. repository) is designed for flexibility. It allows shortlog to be used as both a standalone summarization tool and as a filter for git log output. The terminal detection prevents it from accidentally hanging while waiting for stdin in scripts.

Pre-commit hook specifics: During pre-commit hooks, Git maintains the repository in a semi-detached state. The staging area (index) is being prepared, and there's no guarantee of a current branch context. Always use git shortlog HEAD or git log --pretty=short | git shortlog in hooks.

Bare repositories: In bare repositories (like those on Git servers), always specify revisions explicitly since there's no working tree or current branch concept.

Performance considerations: For large repositories, using revision ranges (e.g., v1.0..HEAD) is more efficient than processing the entire history. Consider using --since or --until flags for time-bounded statistics.

Alternative tools: If you need more robust contributor statistics that work consistently across environments, consider tools like git-fame, git-stats, or parsing git log --format directly with explicit formatting.

Frequently asked questions

What does "fatal: no commits to shortlog" mean?
The "git shortlog no output" error occurs when git shortlog is invoked without proper context or arguments. Git shortlog is designed to summarize git log output, grouping commits by author. However, it has specific behavior that causes it to produce no output in certain scenarios.
How do I fix "fatal: no commits to shortlog"?
Git shortlog returns empty output when run in non-interactive environments like scripts, CI systems, or when no revision is specified. This occurs because shortlog expects either a terminal or explicit revision argument.
What causes "fatal: no commits to shortlog"?
Running git shortlog without arguments in a non-interactive shell or script Executing git shortlog during git hooks when the repository is in a semi-detached state No current branch available when git shortlog is invoked
Is the "fatal: no commits to shortlog" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading