GitHub:包含特定提交的标签

7
在Github上,当您访问与提交相对应的页面 - 像这样 - 您可以看到以下内容:

Commit page

我想象在分支(master)旁边,该页面正在显示包含该特定提交的存储库标签(在本例中为:4.8.0、4.7.1、4.7.0、4.6.2、4.6.14.6.0)。是否有一种通过GitHub REST API或通过GIT命令行工具访问该信息的方法?

1
克隆存储库后,像答案https://dev59.com/72sz5IYBdhLWcg3wZ25q#7923114中所述,运行“git tag --contains a5a5f612e”。 - J.J. Hakala
2个回答

6

我对REST API不确定,但是你可以从Git的CLI中完成这个操作。

git tag --contains <commit>

这将输出从此提交可达的所有标记。 <commit> 可以是提交或对象,例如分支名称、标签名称或 SHA 码。

3

如何通过GitHub REST API或GIT命令行工具访问该信息?

您可以以多种方式获取所有标签的列表。


GitHub API

获取标签
GET /repos/:owner/:repo/git/tags/:sha

响应内容:

{
  "tag": "v0.0.1",
  "sha": "940bd336248efae0f9ee5bc7b2d5c985887b16ac",
  "url": "https://api.github.com/repos/octocat/Hello-World/git/tags/940bd336248efae0f9ee5bc7b2d5c985887b16ac",
  "message": "initial version\n",
  "tagger": {
    "name": "Scott Chacon",
    "email": "schacon@gmail.com",
    "date": "2014-11-07T22:01:45Z"
  },
  "object": {
    "type": "commit",
    "sha": "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
    "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c"
  }
}

git log

git log --decorate --graph --oneline

enter image description here


git tag

git tag --contains <commit>

--包含[<提交>]
仅列出包含指定提交的标签(如果未指定,则为HEAD)。

enter image description here


1
你确定 REST API 的 URL 是正确的吗?我尝试使用你提供的示例中的 URL,但是返回了 404 错误:https://api.github.com/repos/octocat/Hello-World/git/tags/940bd336248efae0f9ee5bc7b2d5c985887b16ac - Guillermo Guardastagno
看起来你有空标签:https://api.github.com/repos/octocat/Hello-World/tags - CodeWizard

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