Github API - 创建分支? [英] Github API - create branch?
问题描述
似乎 v1、v2 和 v3 的Repos"文档中缺少它...如何使用 Github API 创建分支?
V3 API 提到了 branches在其参考页面
<块引用>URL 中的 ref 格式必须为 heads/branch
,而不仅仅是 branch
.
例如,获取名为 sc/featureA
的分支的数据的调用将是:
GET/repos/:user/:repo/git/refs/heads/sc/featureA
创建参考
POST/repos/:user/:repo/git/refs
参数
ref
<块引用>
完全限定引用的名称字符串(即:refs/heads/master).如果它不是以'refs'开头并且至少有两个斜杠,它将被拒绝.
sha
<块引用>
将此引用设置为 SHA1 值的字符串
因此应该可以通过在 ref 参数中命名一个新的/heads
"来创建一个新分支.
Potherca 指出工作测试,使用www.hurl.it
的服务(发出 HTTP 请求)
找到您想要分支的修订版.
无论是在 Github 上还是通过从 Hurl 执行 GET 请求:https://api.github.com/repos/
/ /git/refs/heads 复制修订哈希
从 Hurl 向
https://api.github.com/repos/<AUTHOR>/<REPO>/git/refs
将以下内容作为POST
正文:<代码>{"ref": "refs/heads/
","sha": " "} (显然将
替换为您希望新分支具有的名称和
> 你知道,你想要分支的修订的哈希值)您需要使用 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 justbranch
.
For example, the call to get the data for a branch namedsc/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 thePOST
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屋!