出现提交的分支列表 [英] List of branches a commit appears on

查看:107
本文介绍了出现提交的分支列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GitHub API(v3)我想确定一个提交出现在哪个分支上。我没有找到一种方法直接查询这个,无论是通过repo提交或提交数据对象。另一种解决方案是列出所有分支,并与他们的HEAD进行比较;我猜如果提交不在给定的分支上,比较会失败。

这是通过当前API支持的,我错过了它?如果没有,那么你有一个(更好的)解决方法吗?

解决方案

这不可能直接通过GitHub API。



解决方法1:




  1. get a 所有分支机构的列表

  2. 为每个分支获取一个该分支上的提交列表

  3. 检查提交是否在列表中每个分行的提交次数



解决方法2(我认为这可以工作,但不是100%我错过了一个例子):




  1. get a 所有分支的列表

  2. 对于每个分支,比​​较分支和SHA

    https://api.github。 COM /回购/:用户/:回购/​​比较/:分支...:sha_of_commit


  3. 如果状态属性在响应中是 diverged ahead ,则提交不在分支中。如果状态属性的值是后面相同 ,那么提交就在分支中。



Using the GitHub API (v3) I'd like to figure out which branches a commit appears on. I didn't find a way to directly query this, either through repo commits or the commit data objects. An alternate solution would be to list all the branches, and compare with their HEAD; I guess the comparison would fail if the commit is not on the given branch.

Is this supported via the current API, and I just missed it? If not, do you have a (better) workaround?

解决方案

That's not possible directly via the GitHub API.

Workaround 1:

  1. get a list of all branches
  2. for each branch, get a list of commits on that branch
  3. check if the commit is in the list of commits for each branch

Workaround 2 (I think this will work, but not 100% sure if I missed a case):

  1. get a list of all branches
  2. for each branch, compare the branch with the SHA:

    https://api.github.com/repos/:user/:repo/compare/:branch...:sha_of_commit

  3. If the value of the status attribute in the response is diverged or ahead, then the commit is not in the branch. If the value of the status attribute is behind or identical, then the commit is in the branch.

这篇关于出现提交的分支列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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