Skip to content

Support short SHAs in commit_parsers #1638

Closed

Description

@heaths

Is there an existing issue or pull request for this?

  • I have searched the existing issues and pull requests

Feature description

We can match commits in commit_parsers like so:

commit_parsers = [
  # Rewrite history
  { sha = "20246539df88431c72d65d7d0d1b82fba3deec34", group = "<!-- 0 -->Added" }, # Initial commit
]

However, this is a bit of a hassle since git cliff -vv dumps the short SHA e.g.,

TRACE git_cliff_core::process                   > process_commits: 2024653 - Grouping error: `Commit does not belong to any group` (Initial commit)

I had quite a few and while it wasn't too hard to get the full SHAs, it would be much easier if we could just block copy the short SHAs you already printed out.

Short SHAs (7+ chars) should be plenty for most repos, but people could always use more so any number of unambiguous chars should be supported, erring if there is any ambiguity just like git would.

Desired solution

Support any number of unambiguous short SHAs and err like git would when any ambiguity is hit.

Alternatives considered

Use a script or agent to resolve the short SHAs as needed, which is what I did but it would've been easier to just avoid needing to.

Additional context

No response

Activity

  1. orhun commented on Sep 13, 2026

    @orhun
    Owner

    Sounds good, PR welcome!

  2. removed their assignment
    on Sep 13, 2026
  3. heaths commented on Sep 14, 2026

    @heaths
    ContributorAuthor

    5. Sounds good, PR welcome!

    Well, I had one ready but needed to fix #1640 first and seems @yuefdev published first. I also saw in CONTRIBUTING.md it recommended discussion first. I only submitted the bug fix PR because it was a simple fix and I figured there'd be little discussion needed.

    My change was simpler. It allowed for ambiguity as a simple check when I realized the flow was just doing a simple string match. Could be desirable as a simple !str.starts_with. But if you'd rather take @yuefdev's that does err on ambiguities that's fine, of course. I just worry how that will scale in a large monorepo with thousands of commits.

  4. yuefdev commented on Sep 14, 2026

    @yuefdev
    Contributor

    Thanks @heaths, sorry for the overlap! The ambiguity check in #1642 follows the original request to reject ambiguous prefixes, but your scaling concern is fair. It scans the collected commit IDs once per abbreviated SHA parser, before normal commit processing; I have not benchmarked it on a large monorepo. It also only checks commits included in the changelog, so it is not equivalent to repository-wide Git resolution.

    Your prefix-match approach is simpler if matching multiple commits is acceptable. Happy to align with whichever behaviour you and @orhun prefer; no need to favour #1642 because it landed first.

  5. heaths commented on Sep 14, 2026

    @heaths
    ContributorAuthor

    It also only checks commits included in the changelog, so it is not equivalent to repository-wide Git resolution.

    Good point. I noted that when I reviewed but forgot it while writing the comment.

    Your prefix-match approach is simpler if matching multiple commits is acceptable.

    I'm fine either way. Whatever @orhun prefers. A simple substring match (starts_with, not just anywhere) could be useful but may also—though mathematically improbable after a certain number of chars—inadvertently surprise people if another substring match occurs unexpectedly. As you noted, the perf impact is at least lessened since you're only resolving short SHAs authored into commit_parsers. My gut: yours is safest.

  6. yuefdev commented on Sep 30, 2026

    @yuefdev
    Contributor

    Thanks for checking it over! Agreed on avoiding surprises from ambiguous prefixes. Happy to follow whichever behaviour @orhun prefers.

  7. orhun commented on Oct 31, 2026

    @orhun
    Owner

    I agree we should reject ambiguous prefixes to avoid surprising matches.

  8. added a commit that references this issue on Oct 31, 2026
    a81737c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions