Von*_*onC 52
URL中的引用必须格式化为
heads/branch,而不仅仅是branch.
例如,获取命名分支的数据的调用sc/featureA将是:
GET /repos/:user/:repo/git/refs/heads/sc/featureA
Run Code Online (Sandbox Code Playgroud)
POST /repos/:user/:repo/git/refs
Run Code Online (Sandbox Code Playgroud)
ref
Run Code Online (Sandbox Code Playgroud)
完全限定引用的名称的字符串(即:refs/heads/master).如果它不以'refs'开头且至少有两个斜杠,则会被拒绝.
sha
Run Code Online (Sandbox Code Playgroud)
用于设置此引用的SHA1值的字符串
因此,应该可以通过/heads在ref参数中命名一个新的' 来创建一个新的分支.
Potherca 指出到一个工作测试,使用的服务www.hurl.it(这使得HTTP请求)
找到要分支的修订版本.
无论是在Github上还是从Hurl做一个GET请求:
https://api.github.com/repos/<AUTHOR>/<REPO>/git/refs/heads复制修订哈希
从Hurl执行POST请求
https://api.github.com/repos/<AUTHOR>/<REPO>/git/refs,并将以下内容作为POST正文:Run Code Online (Sandbox Code Playgroud){ "ref": "refs/heads/<NEW-BRANCH-NAME>", "sha": "<HASH-TO-BRANCH-FROM>" }(显然用
<NEW-BRANCH-NAME>你想要新分支的名称替换你想要分支<HASH-TO-BRANCH-FROM>的修订版的哈希值)您将需要使用HTTP basic并填写您的Github凭据以访问Github API.
按发送按钮,您的分支将被创建!
这是我们在GitHub中创建用于创建分支的API时所有学生的共同问题
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
Run Code Online (Sandbox Code Playgroud)
为了在 Github 中创建存储库期间解决此错误.....
首先在中创建一个个人令牌
Github=>setting=>developerOption=>generatePersonalToken...
or
Run Code Online (Sandbox Code Playgroud)
在 gitLogin bu Oauth 期间,当您传递 client_id 时传递 scope=repo(因为当您使用令牌或任何东西时,它允许所有存储库)
之后:点击 API(get)
https://api.github.com/repos/<your login name>/<Your Repository Name>/git/refs/heads
你得到了这样的回应
Response => {
[
{
"ref": "refs/heads/<already present branch name for ref>",
"node_id": "jkdhoOIHOO65464edg66464GNLNLnlnnlnlna==",
"url": " https://api.github.com/repos/<your login name>/<Your Repository Name>/git/refs/heads/<already present branch name for ref>",
"object": {
"sha": "guDSGss85s1KBih546465kkbNNKKbkSGyjes56",
"type": "commit",
"url": " https://api.github.com/repos/<your login name>/<Your Repository Name>/git/commits/guDSGss85s1KBih546465kkbNNKKbkSGyjes56"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)完成这个过程再次命中API(Post)
https://api.github.com/repos/Bhupi2508/Test/git/refs...
Run Code Online (Sandbox Code Playgroud)
并以 JSON 格式发送数据,如下所示:
{
"ref": "refs/heads/<new branch name>",
"sha": "4661616ikgohlKIKHBK4634GRGSD66"
}
Run Code Online (Sandbox Code Playgroud)
然后你在 GITHUB 中通过 API 创建一个分支
并且删除分支的过程只命中了 DELETE(第一个)API
添加到@VonC 答案,这里是 python 中的工作片段。
import requests
headers = {'Authorization': "Token " + 'YOUR_TOKEN_HERE'}
url = "https://api.github.com/repos/<USERNAME>/<REPO>/git/refs/heads"
branches = requests.get(url, headers=headers).json()
branch, sha = branches[-1]['ref'], branches[-1]['object']['sha']
res = requests.post('https://api.github.com/repos/<USERNAME>/<REPO>/git/refs', json={
"ref": "refs/heads/newbranch",
"sha": sha
}, headers=headers)
print(res.content)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14424 次 |
| 最近记录: |