【问题标题】:How do I find the default branch for a repository using the Github v3 API如何使用 Github v3 API 找到存储库的默认分支
【发布时间】:2013-05-06 05:05:59
【问题描述】:

我的目标是在默认分支中获取最新 SHA 的树

GET /repos/:owner/:repo/git/trees/:sha

如何从默认分支中找到最新的 SHA?

我知道我可以打电话

GET /repos/:owner/:repo/branches/:branch

但我不能只使用“master”作为分支,因为并非所有 repos 都使用 master 作为默认分支。

如何找出 repo 的默认分支是什么?

【问题讨论】:

    标签: github-api


    【解决方案1】:

    调用/repos/:owner/:repo 并读取default_branch 属性值 - 这是默认分支的名称。在此处查看示例响应:http://developer.github.com/v3/repos/#get

    【讨论】:

    • 100% 这个。此外,如果您使用任何好的包装库,它们都应该让您轻松访问它。
    • 实际上有“default_branch”键。
    • @android 嘿,你是对的——有两个键:master_branch 键和default_branch 键。你知道有什么区别吗?我猜它们总是具有相同的值,并且在某个时间点不推荐使用一个键。
    • @android 有时 default_branch 是空的 (nil) 而 master_branch 不是,有时两者都不是空的。我还没有找到它的原因,坦率地说,我觉得这对 API 团队来说并不重要。
    • master_branch 仅用于向后兼容。 default_branch 将替换next version of the API 中的master_branch
    猜你喜欢
    • 2018-08-02
    • 2016-02-13
    • 2019-04-13
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 2018-07-06
    • 2019-12-26
    • 2016-06-06
    相关资源
    最近更新 更多