git-cliff icon indicating copy to clipboard operation
git-cliff copied to clipboard

Make git short sha (SHA-1) available

Open hmvp opened this issue 6 months ago • 4 comments

Is there an existing issue or pull request for this?

  • [x] I have searched the existing issues and pull requests

Feature description

I want to generate links to the gitlab webinterface for commits like [{{ commit.id }}](https://gitlab.something.com/user/project/commits/{{ commit.id }}) but the full id is quite long and I rather use the short sha as the git cli provides it...

Desired solution

I would like to be able use commit.short_id or something next to commit.id in templates

Alternatives considered

A template filter that converts the long sha into a short one. This will not work as expected because git does some magic to adapt the length of the short sha so that there is low chance on collisions.

Additional context

No response

hmvp avatar May 19 '25 15:05 hmvp

Thanks for opening your first issue at git-cliff! Be sure to follow the issue template! ⛰️

welcome[bot] avatar May 19 '25 15:05 welcome[bot]

You can use the truncate filter for this, e.g.

{{ previous.commit_id | truncate(length=7, end="") }}

orhun avatar May 26 '25 17:05 orhun

While truncate will help it it technically not the same...

From the git book:

Git can figure out a short, unique abbreviation for your SHA-1 values. If you pass --abbrev-commit to the git log command, the output will use shorter values but keep them unique; it defaults to using seven characters but makes them longer if necessary to keep the SHA-1 unambiguous:

hmvp avatar May 26 '25 17:05 hmvp

Ah got it, you want SHA-1

It would be nice to add a custom filter (similar to upper_first) then!

orhun avatar May 26 '25 17:05 orhun