go-git:创建短哈希(a83ad00 而不是 a83ad004b3c5…)

huangapple go评论68阅读模式
英文:

go-git: Create short hash (a83ad00 instead of a83ad004b3c5...)

问题

我正在使用go-git,我想要打印出短哈希。

我的意思是,例如"a83ad00"而不是"a83ad004b3c5971a194ba86b96fe313b94bbcde7"。

我查看了go-git的源代码,但找不到相应的函数。

如何获取短的"partial"哈希?

英文:

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?

答案1

得分: 1

你可以使用字符串截取吗?我在API文档中没有看到相关内容。

full := repo.Head().Hash().String()
short := full[0:8]
英文:

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

full := repo.Head().Hash().String()
short := full[0:8]

huangapple
  • 本文由 发表于 2022年7月5日 14:34:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/72864903.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定