如何在存储库中获取最新的git commit SHA-1?

How to get the latest git commit SHA-1 id in a repository?

如何在存储库中获取最新的git commit SHA-1 id?

And how to get the first 8 digits of the SHA-1?

以及如何获得SHA-1的前8位数字?

Instead of the method introduced here, you may use

除了此处介绍的方法,您可以使用

$ git rev-parse HEAD

to get the commit SHA-1 hash ID.

获取提交SHA-1哈希ID。

If you want to get the first 8 digits only, use

如果只想获取前8位数字,请使用

$ git rev-parse HEAD | cut -c 1-8

Here, cut -c 1-8 gives you bytes 1 to 8.

在这里, cut -c 1-8为您提供字节1至8。

BTW: if you have tags tagging the versions, you may use

顺便说一句:如果您有标记版本的标签,则可以使用

$ git describe --tags --long

to get a better string for IDs like

为ID之类的字符串获取更好的字符串

v2.0-40-gdc25d60

Here, ‘v2.0′ is the latest tag. ’40’ is the number of commits after the ‘v2.0’ tag and ‘gdc25d60’ is the first 8 digits of the commit sha-1 hash ID.

在此,“ v2.0”是最新的标签。 “ 40”是在“ v2.0”标签之后的提交次数,而“ gdc25d60”是提交sha-1哈希ID的前8位。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/how-to-get-the-latest-git-commit-sha-1-in-a-repository/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值