Branches API

原文:https://docs.gitlab.com/ee/api/branches.html

Branches API

该 API 在存储库分支上运行 .

提示:另请参阅受保护的分支机构 API .

List repository branches

从项目中获取存储库分支的列表,按名称的字母顺序排序.

注意:如果可公开访问该存储库,则无需身份验证即可访问此端点.

GET /projects/:id/repository/branches 

Parameters:

Attribute Type Required Description
id integer/string yes 身份验证用户拥有的项目的 ID 或URL 编码路径 .
search string no 返回包含搜索字符串的分支列表. 您可以使用^termterm$查找分别以term开头和结尾的分支.

请求示例:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/branches" 

响应示例:

[  {  "name":  "master",  "merged":  false,  "protected":  true,  "default":  true,  "developers_can_push":  false,  "developers_can_merge":  false,  "can_push":  true,  "web_url":  "http://gitlab.example.com/my-group/my-project/-/tree/master",  "commit":  {  "author_email":  "john@example.com",  "author_name":  "John Smith",  "authored_date":  "2012-06-27T05:51:39-07:00",  "committed_date":  "2012-06-28T03:44:20-07:00",  "committer_email":  "john@example.com",  "committer_name":  "John Smith",  "id":  "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",  "short_id":  "7b5c3cc",  "title":  "add projects API",  "message":  "add projects API",  "parent_ids":  [  "4ad91d3c1144c406e50c7b33bae684bd6837faf8"  ]  }  },  ...  ] 

Get single repository branch

获取单个项目存储库分支.

注意:如果可公开访问该存储库,则无需身份验证即可访问此端点.

GET /projects/:id/repository/branches/:branch 

Parameters:

Attribute Type Required Description
id integer/string yes 身份验证用户拥有的项目的 ID 或URL 编码路径 .
branch string yes 分支名称.

请求示例:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/branches/master" 

响应示例:

{  "name":  "master",  "merged":  false,  "protected":  true,  "default":  true,  "developers_can_push":  false,  "developers_can_merge":  false,  "can_push":  true,  "web_url":  "http://gitlab.example.com/my-group/my-project/-/tree/master",  "commit":  {  "author_email":  "john@example.com",  "author_name":  "John Smith",  "authored_date":  "2012-06-27T05:51:39-07:00",  "committed_date":  "2012-06-28T03:44:20-07:00",  "committer_email":  "john@example.com",  "committer_name":  "John Smith",  "id":  "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",  "short_id":  "7b5c3cc",  "title":  "add projects API",  "message":  "add projects API",  "parent_ids":  [  "4ad91d3c1144c406e50c7b33bae684bd6837faf8"  ]  }  } 

Protect repository branch

有关保护存储库分支的信息,请参见POST /projects/:id/protected_branches .

Unprotect repository branch

有关取消保护存储库分支的信息,请参见DELETE /projects/:id/protected_branches/:name .

Create repository branch

在存储库中创建一个新分支.

POST /projects/:id/repository/branches 

Parameters:

Attribute Type Required Description
id integer yes 身份验证用户拥有的项目的 ID 或URL 编码路径 .
branch string yes 分支名称.
ref string yes 分支名称或提交 SHA 以从中创建分支.

请求示例:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/branches?branch=newbranch&ref=master" 

响应示例:

{  "commit":  {  "author_email":  "john@example.com",  "author_name":  "John Smith",  "authored_date":  "2012-06-27T05:51:39-07:00",  "committed_date":  "2012-06-28T03:44:20-07:00",  "committer_email":  "john@example.com",  "committer_name":  "John Smith",  "id":  "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",  "short_id":  "7b5c3cc",  "title":  "add projects API",  "message":  "add projects API",  "parent_ids":  [  "4ad91d3c1144c406e50c7b33bae684bd6837faf8"  ]  },  "name":  "newbranch",  "merged":  false,  "protected":  false,  "default":  false,  "developers_can_push":  false,  "developers_can_merge":  false,  "can_push":  true,  "web_url":  "http://gitlab.example.com/my-group/my-project/-/tree/newbranch"  } 

Delete repository branch

从存储库中删除一个分支.

注意:如果发生错误,将提供说明消息.

DELETE /projects/:id/repository/branches/:branch 

Parameters:

Attribute Type Required Description
id integer/string yes 身份验证用户拥有的项目的 ID 或URL 编码路径 .
branch string yes 分支名称.

请求示例:

curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/branches/newbranch" 

Delete merged branches

Will delete all branches that are merged into the project’s default branch.

注意:此操作不会删除受保护的分支 .

DELETE /projects/:id/repository/merged_branches 

Parameters:

Attribute Type Required Description
id integer/string yes 身份验证用户拥有的项目的 ID 或URL 编码路径 .

请求示例:

curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/merged_branches" 
Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2021-03-27 13:48:25
鼓励一下

results matching ""

    No results matching ""