Mastering Git Logs: How to List Commits Between Two Points (Excluding Merges)

Mastering Git Logs: How to List Commits Between Two Points (Excluding Merges)
Photo by Antoine Dautry / Unsplash

When working with Git, it’s common to review a series of commits between two points in history. Maybe you want to generate release notes, review code history, or export commit data for auditing. But if you’ve worked with teams, you’ll often see merge commits cluttering the history, which aren’t always useful in such reports.

This article will walk you through how to list commits from a specific commit hash up to the latest (HEAD) while excluding merge commits, and also include details such as the commit hash, author, date, subject, and description.


The Core Command

Let’s say you want all commits starting from commit:

fd78c6c93fa424234aba70f15f125a6382b07038

and ending at the latest commit (HEAD). The following command gives you exactly that:

git log fd78c6c93fa424234aba70f15f125a6382b07038..HEAD --no-merges \
  --pretty=format:"%H%nAuthor: %an <%ae>%nDate: %ad%nSubject: %s%n%b%n---"

Breaking It Down

  • fd78c6c93fa424234aba70f15f125a6382b07038..HEAD
    Defines the commit range: from that commit (exclusive) up to HEAD (inclusive).
  • --no-merges
    Excludes merge commits, so you only see meaningful changes.
  • --pretty=format:"..."
    Allows custom formatting. Here, we show:
    • %H → Full commit hash
    • %an → Author name
    • %ae → Author email
    • %ad → Author date (uses your Git config format)
    • %s → Commit subject (the short message)
    • %b → Commit body (the description, if any)
    • %n → New line
    • --- → Separator between commits for readability

Example Output

c1a2b3d4e5f6g7h8i9j0
Author: John Doe <[email protected]>
Date: Mon Oct 2 10:25:33 2025 +0700
Subject: Fix login issue
Added validation for empty tokens to prevent crash

---
a1b2c3d4e5f6g7h8i9j0
Author: Jane Smith <[email protected]>
Date: Sun Sep 28 14:12:09 2025 +0700
Subject: Improve logging
Refactored error handler and added stack trace

---

This makes it easy to read, share, or even generate release notes from your commit history.


Including the Starting Commit

By default, the syntax A..B does not include commit A. If you also want to include the starting commit, you can use:

git log fd78c6c93fa424234aba70f15f125a6382b07038^..HEAD --no-merges

The ^ means “the parent of that commit,” which effectively includes the starting commit itself in the range.


Date Formatting Options

If you need dates in a consistent machine-readable format (for example, for CSV export or scripting), you can replace %ad with %ai:

  • %ad → Author date (human-readable, e.g., “Mon Oct 2 10:25:33 2025 +0700”)
  • %ai → Author date in ISO 8601 format (e.g., “2025-10-02 10:25:33 +0700”)

Exporting to a File

Sometimes, you want to save the output for documentation or reporting. Just redirect the command to a file:

git log fd78c6c93fa424234aba70f15f125a6382b07038..HEAD --no-merges \
  --pretty=format:"%H%nAuthor: %an <%ae>%nDate: %ai%nSubject: %s%n%b%n---" > commit-history.txt

Now you’ll have a clean text file with all commit details.


CSV or Script-Friendly Format

If you want to export in a single-line format (easier for Excel or parsing), you can try:

git log fd78c6c93fa424234aba70f15f125a6382b07038..HEAD --no-merges \
  --pretty=format:"%H|%an|%ae|%ai|%s|%b"

This will output each commit as a pipe-delimited row, which can be easily imported into a spreadsheet or processed by scripts.


Additional Considerations

Patch Mode
If you need the actual code changes too:

git log fd78c6c93fa424234aba70f15f125a6382b07038..HEAD --no-merges -p

Filtering by File or Directory
To see changes only related to a specific file:

git log fd78c6c93fa424234aba70f15f125a6382b07038..HEAD --no-merges -- path/to/file

Filtering by Author
If you only want commits by a specific author:

git log fd78c6c93fa424234aba70f15f125a6382b07038..HEAD --no-merges --author="John Doe"

Finally

With just a small adjustment to git log, you can extract meaningful commit histories that exclude merges and show all the details you care about: hash, author, date, subject, and description. This approach is useful not only for personal review but also for creating release notes, audit logs, and changelogs in a clear, human-readable format.

If you often generate such logs, consider wrapping the command into a Git alias or script so it becomes part of your daily workflow.

Support Us

Share to Friends