仅使用HTTP获取存储库的当前HEAD的哈希 [英] Get the hash of the current HEAD of a repository using only HTTP

查看:88
本文介绍了仅使用HTTP获取存储库的当前HEAD的哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,如果我已签出Git存储库,则可以使用git CLI来获取当前的提交哈希.但是,有没有一种方法可以仅通过HTTP来执行此操作,而无需克隆存储库?

I know that if I have a Git repository checked out, I can use the git CLI to get the current commit hash. But is there a way to do this just over HTTP, without cloning the repository?

例如,假设我要获取 https://github.com/jashkenas的当前哈希/coffeescript .手动地,我可以转到页面,在键盘上按Y,然后看到哈希值(在撰写本文时)为1f197fcc1bf1a15bc45a6b23fb3f706ffcb77025.这意味着,如果稍后我想下载CoffeeScript源代码,可以下载

For example, let's say that I want to get the current hash of https://github.com/jashkenas/coffeescript. Manually, I can go to the page, press Y on my keyboard, and see that the hash is (at the time of this writing) 1f197fcc1bf1a15bc45a6b23fb3f706ffcb77025. Which means that if at some later point I wanted to download the CoffeeScript source as it is at this moment, I could download https://github.com/jashkenas/coffeescript/archive/1f197fcc1bf1a15bc45a6b23fb3f706ffcb77025.zip, and it would give me the source.

是否仅使用HTTP(例如curl)就能做到这一点?我可以点击某个端点来告诉我默认分支的当前哈希值是什么吗?概括一下,是否有端点可以告诉我

Is there a way to do this just using HTTP (e.g. curl)? Can I hit some endpoint which will tell me what the current hash is of the default branch? Generalizing a bit, are there endpoints which will tell me the hash of

  • 默认分支的HEAD
  • 给定分支的HEAD,或
  • 一个特定的标签?

推荐答案

如果您想在GitHub上专门获取此信息,则可以使用

If you wanted this information on GitHub specifically, you could retrieve it using the GitHub API, which will return a somewhat large JSON structure with exhaustive information on the state of that branch:

https://api.github.com/repos/jashkenas/coffeescript/branches/master

(或删除分支名称,以更简洁地列出所有分支及其头.)

(Or remove the branch name to get a more terse listing of all branches and their heads.)

对于托管在其他Web服务上的Git存储库,可以在存储库(例如http://example.com/repo.git/info/refs)下获取资源/info/refs以获得所有分支的列表,例如:

For Git repositories hosted on other web services, it's possible to fetch the resource /info/refs under the repository (e.g, http://example.com/repo.git/info/refs) to get a listing of all branches, e.g.:

2aae6c35c94fcfb415dbe95f408b9ce91ee846ed    refs/heads/master

但是,该功能在GitHub上不可用,因为.替代的智能"运输工具虽然可以供Git自己使用,但在这种情况下无法使用.

However, this is not available on GitHub, because GitHub disabled the "dumb" HTTP transport in 2011 for performance reasons. The replacement "smart" transport, while far superior for Git's own use, isn't usable outside that context.

这篇关于仅使用HTTP获取存储库的当前HEAD的哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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