如何在不克隆Git存储库的情况下获取SHA1哈希值?

6

如果U是一个 git URL(例如,一个 ssh URL),我如何在没有本地克隆U的情况下找到U分支或标签的 SHA1 哈希值?

3个回答

8

或者使用 git ls-remote 命令获取整个存储库的哈希值。 - Nathaniel Ford
1
@NathanielFord:当然,如果您当前的目录是要查询的Git存储库(即如果您已经克隆了存储库),那么可以这样做。指定URL可以让您从任何地方运行命令。 - ellotheth

1
您可以使用以下命令: git ls-remote U branch | cut -c1-7 其中,'branch' 指定了特定分支的提交哈希值。

0

如果您使用git ls-remote,请确保使用Git 2.28 (2020年第三季度),因为SHA-256迁移工作仍在继续。
自Git 2.19 (2018年第二季度)以来,Git准备将哈希从SH1转换为SHA2,详见 "为什么Git不使用更现代的SHA算法?"

请查看 commit 3716d50, commit 6161ce7, commit 371c407, commit 4ddd3f5, commit f7c6a3b, commit 8fc7003, commit 54cbbe4, commit 97997e6, commit 793731f, commit 586740a, commit ac093d0 (2020年6月19日), commit d96dab8, commit f0af95f, commit 9de0dd3, commit ab67235, commit 67e9a70, commit 7f46e7e, commit 059d806, commit 88a09a5, commit 1610dda, commit 629dffc, commit 49c9a2f, commit d553ace, commit 4b83120, commit 9dc78c2, commit b65dc2c, commit 7f60501, commit 8b85ee4, commit 452e356, commit bb095d0, commit 7c601dc, commit 48bf141, commit 84eca27, commit 82db03a, commit 122037c, commit 7c97af4, commit 9a9f0d3, commit 1349ffe, commit 2c6a403, commit bf30dbf, commit 14570dc, commit 92315e5 (2020年5月25日), 以及 commit b8615c3, commit a114296 (2020年5月13日) 由 brian m. carlson (bk2204) 提交。
(由 Junio C Hamano -- gitster -- 合并于 commit 1221085, 2020年7月6日)

remote-curl:避免使用 ls-remote 截断引用

签名作者:brian m. carlson

通常情况下,remote-curl 传输助手会意识到我们正在使用的哈希算法,因为我们在具有适当哈希算法设置的存储库中。

然而,在存储库之外使用 git ls-remote 时,我们将无法正确初始化哈希算法,因此使用 hash_to_hex_algop 打印对应于我们检测到的算法的引用。

这很重要,因为在您的情况下,您将在任何本地 Git 存储库之外使用 git ls-remote U


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接