是否可以在不首先使用 GitPython(或更普遍的 Git)克隆存储库的情况下检索当前 HEAD 的提交 ID?

Is it possible to retrieve the commit ID of the current HEAD without first cloning the repository using GitPython (or more generally Git)?

我正在开发一个程序来分析 Git 存储库的内容,如果它们发生了变化(即当前 HEAD 的提交 ID 发生了变化)

由于有超过 10.000 个存储库,并且只有相对较少的存储库正在积极开发中,我想避免在检查其当前 HEAD 的提交 ID 之前必须克隆所有存储库.

GitPython 是否支持此功能 - 更一般地说,Git 是否支持在不克隆存储库的情况下检查 refs 的值?

NB:我可以做一个 clone --bare --depth 1 <repo> [<dir>] 只检索最新提交的对象,而不检查 HEAD,这会加快速度涨幅可观。但是,如果我只想检查当前 HEAD.

的提交 ID,我仍然需要下载最新提交的所有对象,这仍然是浪费精力

注意:Git 服务提供商 (Stash) 不支持 clone --filter ... 选项,可以用来避免下载任何 blob?

使用git ls-remote

git ls-remote repo-or-remote master

会给你master的哈希(你可以检查任何分支)

git ls-remote repo-or-remote

将为您提供远程上所有可用引用的哈希值,使用--heads仅查看分支