0

I am using go-git and I would like to print the short hash.

I mean, for example "a83ad00" instead of "a83ad004b3c5971a194ba86b96fe313b94bbcde7".

I looked at the source code of got-git, but could not find a corresponding function.

How to get the short "partial" hash?

guettli
  • 25,042
  • 81
  • 346
  • 663

1 Answers1

1

Couldn't you substring it? I do not see any from the API docs

full := repo.Head().Hash().String()
short := full[0:8]
shyam
  • 9,134
  • 4
  • 29
  • 44
  • But this could fail, if there is already a different commit with the same short hash. AFAIK this simple way does not work. – guettli Jul 05 '22 at 08:25