Github API - 创建分支? [英] Github API - create branch?

查看:268
本文介绍了Github API - 创建分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎从v1,v2和v3的Repos文档中缺少它......如何使用Github API创建分支?

解决方案

V3 API在其参考页面中提到分支


URL中的ref必须格式化为 heads / branch ,而不仅仅是分支

例如,调用以获取名为 sc / featureA 应该是:



  GET / repos /:user / :repo / git / refs / heads / sc / featureA 



创建参考



  POST / repos /:user /:repo / git / refs 



参数



  ref 




完全限定引用的名称的字符串(即:refs / heads / master)。



 <$如果它不以'refs'开头并且至少有两个斜杠,它将被拒绝。 c $ c> sha 




设置此引用的SHA1值的字符串到


所以应该可以创建一个新的分支,通过命名一个新的 / heads

code>'的参数。






Potherca 指出 a>转到 工作测试 ,使用 www.hurl.it (其中发出HTTP请求)



  • 找到您想要从中分支的修订。

    Eit她在Github本身或者通过从Hurl获取GET请求:


    https://api.github.com/repos/<AUTHOR> /< REPO> / git / refs / heads


  • 复制修订哈希

  • $ b
  • 从Hurl执行POST请求至 https://api.github.com/repos/<AUTHOR> /< REPO> / git / ref ,其中 POST 正文:

      {
    ref:refs / heads /< NEW-BRANCH-NAME>,
    sha:< HASH-TO-BRANCH-FROM>

    $ / code>

    (显然替换< NEW-BRANCH- NAME> ,您希望新分支的名称和< HASH-TO-BRANCH-FROM> ,您知道,您需要使用HTTP basic并填写您的Github凭据以访问Github API。


  • 按发送按钮即可创建分支!




Seems like it's missing from the "Repos" docs for v1, v2, and v3...how do I create a branch using the Github API?

解决方案

The V3 API mentions branches in its reference page

The ref in the URL must be formatted as heads/branch, not just branch.
For example, the call to get the data for a branch named sc/featureA would be:

GET /repos/:user/:repo/git/refs/heads/sc/featureA

Create a Reference

POST /repos/:user/:repo/git/refs

Parameters

ref

String of the name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and have at least two slashes, it will be rejected.

sha

String of the SHA1 value to set this reference to

So it should be possible to create a new branch, by naming a new '/heads' in the ref parameter.


Potherca points out to a working test, using the service of www.hurl.it (which makes HTTP requests)

  • Find the revision you want to branch from.
    Either on Github itself or by doing a GET request from Hurl:

    https://api.github.com/repos/<AUTHOR>/<REPO>/git/refs/heads

  • Copy the revision hash

  • Do a POST request from Hurl to https://api.github.com/repos/<AUTHOR>/<REPO>/git/refs with the following as the POST body :

    {
        "ref": "refs/heads/<NEW-BRANCH-NAME>",
        "sha": "<HASH-TO-BRANCH-FROM>"
    }
    

    (obviously replacing the <NEW-BRANCH-NAME> with the name your want the new branch to have and the <HASH-TO-BRANCH-FROM> with, you know, the hash of the revision you want to branch from)

    You will need to use HTTP basic and fill in your Github credentials to access the Github API.

  • Press the Send button and your branch will be created!

这篇关于Github API - 创建分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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