0

Some of my CI/CD-Workflows depend on the commit-hash of git and I noticed one digit disappeared when I'm using:

echo $(git log --pretty=format:'%h' -n 1)
f7dc8fd

In the command-line to obtain the hash - notice the 7 digits. (Usually I save it for further usage)

On Gitlab the hash is different. 8 digits.

The hash on Gitlab: Notice 8 digits

It seems to be new, it used to be the same. How to sync it again? Should a different command or configuration be used?

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
Qohelet
  • 1,459
  • 4
  • 24
  • 41
  • Maybe the disappeared digita a pre-pended zero? – Antonio Petricca Aug 30 '21 at 14:01
  • 2
    The commit hash didn't change. It's still 40-digit. The short hash you're refering to is but a convention, you can use any number (at least 4 though) of digits as long as it's unique in the repo. – Romain Valeri Aug 30 '21 at 14:03
  • @AntonioPetricca - you can see there are no zeros – Qohelet Aug 30 '21 at 14:08
  • 2
    I suspect the length of the abbreviated hash depends on the commit history. Mine are already 9-char. – Álvaro González Aug 30 '21 at 14:08
  • @RomainValeri - I am aware it's still the "same" short-hash. I'm confused about the fact out of the sudden it changed. Is there a better way to obtain in in the command-line than `git log`? – Qohelet Aug 30 '21 at 14:09
  • @ÁlvaroGonzález - they are 9 char when you execute `echo $(git log --pretty=format:'%h' -n 1)` – Qohelet Aug 30 '21 at 14:10
  • 3
    Does this answer your question? [git log abbreviated format length](https://stackoverflow.com/questions/36489841/git-log-abbreviated-format-length) – Elias Holzmann Aug 30 '21 at 14:11
  • 1
    @EliasHolzmann - yes it does. Thank you. I will replace the `--pretty` with `git log -1 --format=%h --abbrev=8` – Qohelet Aug 30 '21 at 14:25

0 Answers0