gpt4 book ai didi

Github API - 创建分支?

转载 作者:IT王子 更新时间:2023-10-29 01:01:12 26 4
gpt4 key购买 nike

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

最佳答案

V3 API 提到 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

创建引用

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

参数

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

所以应该可以创建一个新的分支,通过命名一个新的'/heads ' 在 ref 参数中。


Potherca points out working test ,使用 www.hurl.it 的服务(发出 HTTP 请求)

  • 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!


2022年还可以用gh api

gh api \
--method POST \
-H "Accept: application/vnd.github.v3+json" \
/repos/OWNER/REPO/git/refs \
-f ref='refs/heads/featureA'
-f sha='aa218f56b14c9653891f9e74264a383fa43fefbd'

关于Github API - 创建分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9506181/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com