简体   繁体   中英

GitHub : Tags that include a specific commit

On Github, when you access the page corresponding to a commit - like this - you can see the following:

提交页面

I imagine that next to the branch ( master ) the page is showing the repository tags that include that specific commit (in this case: 4.8.0, 4.7.1, 4.7.0, 4.6.2, 4.6.1 and 4.6.0 ).

Is there a way to access that information through GitHub REST API, or through GIT command line tools?

I'm not sure about the REST API, but you can do this from Git's CLI

git tag --contains <commit>

This will output all tags reachable from this commit. <commit> can be a commit or object... ie a branch name, tag name, or sha.

Is there a way to access that information through GitHub REST API, or through GIT command line tools?

You can get a list of all your tags in various ways.


GitHub API

Get a Tag
GET /repos/:owner/:repo/git/tags/:sha

The response:

{
  "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

在此处输入图片说明


git tag

git tag --contains <commit>

--contains [<commit>]
Only list tags which contain the specified commit (HEAD if not specified).

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM