git标签对象的格式是什么?如何计算其SHA? [英] What is the format of a git tag object and how to calculate its SHA?

查看:130
本文介绍了git标签对象的格式是什么?如何计算其SHA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉 Git如何为文件(blob)创建SHA1哈希,但不熟悉如何为标签创建它们对象.如果创建带注释的标签,我想是的,但是配方是什么?以及如何在Git之外复制它(例如,在Perl或Python中)?

I am familiar with how Git creates SHA1 hashes for files (blobs), but not how they are created for tag objects. I assume they are, if I create an annotated tag, but what is the recipe? And how might I replicate it outside of Git (e.g., in Perl or Python)?

推荐答案

模式基本上是:

sha1("tag " + datasize + "\0" + data)

其中datagit cat-file的输出.可以通过管道输出到git-hash-object来实现这一点,就像这样:

Where data is the output of git cat-file. One can produce this by piping that output to git-hash-object like so:

git cat-file tag v0.30 | git hash-object -t tag --stdin

等效的perl单线是:

And the equivalent a perl one-liner is:

git cat-file tag v0.30 | perl -MDigest::SHA1 -E '$/=undef;$_=<>;say Digest::SHA1->new->add("tag ".length()."\0".$_)->hex digest'

似乎只需将"tag "替换为适当的对象名称即可将其用于任何类型的对象:"blob ""tree ""commit ".

It seems that one can do this same thing with any of the types objects simply by replacing "tag " with the proper object name: "blob ", "tree ", or "commit ".

这篇关于git标签对象的格式是什么?如何计算其SHA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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