git从常规散列获得短散列 [英] git get short hash from regular hash

查看:125
本文介绍了git从常规散列获得短散列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个常规的长SHA-1哈希字符串。我希望得到最短的,明确的SHA-1哈希字符串版本。也就是说,我会通过使用 git log -1 --pretty = format:%h 得到的,假设长哈希表示最后的提交。

I have a regular long SHA-1 hash string. I would like to get the shortest unambiguous SHA-1 hash string version of it. That is, the one I would get by using git log -1 --pretty=format:%h, assuming the long hash refers to the last commit.

推荐答案

你可以得到的最短SHA1的长度为4.Rev解析会给你一个默认7的SHA1和short选项: / p>

The shortest SHA1 you can get has a length of 4. Rev parse will give you a SHA1 of 7 by default with the short option :

git rev-parse --short 921103db8259eb9de72f42db8b939895f5651489
921103d

您必须指定4作为short选项才能拥有最短的明确SHA1:

You have to specify 4 to the short option to have the shortest unambiguous SHA1 :

git rev-parse --short=4 921103db8259eb9de72f42db8b939895f5651489
92110

这篇关于git从常规散列获得短散列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆