{{< details >}}
- Tier: 基础版,专业版,旗舰版
- Offering: JihuLab.com,私有化部署
{{< /details >}}
该 API 在 代码库分支 上操作。
另请参阅 受保护分支 API。
列出代码库分支
从项目中获取代码库分支列表,按名称字母顺序排序。
{{< alert type=”note” >}}
如果代码库是公开访问的,则可以在不进行身份验证的情况下访问此端点。
{{< /alert >}}
GET /projects/:id/repository/branches
参数:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer 或 string | 是 | 项目的 ID 或 URL 编码路径。 |
search |
string | 否 | 返回包含搜索字符串的分支列表。使用 ^term 查找以 term 开头的分支,使用 term$ 查找以 term 结尾的分支。 |
regex |
string | 否 | 返回名称匹配 re2 正则表达式的分支列表。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/repository/branches"
示例响应:
[
{
"name": "main",
"merged": false,
"protected": true,
"default": true,
"developers_can_push": false,
"developers_can_merge": false,
"can_push": true,
"web_url": "https://gitlab.example.com/my-group/my-project/-/tree/main",
"commit": {
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
"short_id": "7b5c3cc",
"created_at": "2024-06-28T03:44:20-07:00",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
],
"title": "add projects API",
"message": "add projects API",
"author_name": "John Smith",
"author_email": "john@example.com",
"authored_date": "2024-06-27T05:51:39-07:00",
"committer_name": "John Smith",
"committer_email": "john@example.com",
"committed_date": "2024-06-28T03:44:20-07:00",
"trailers": {},
"extended_trailers": {},
"web_url": "https://gitlab.example.com/my-group/my-project/-/commit/7b5c3cc8be40ee161ae89a06bba6229da1032a0c"
}
},
...
]
获取单个代码库分支
获取单个项目代码库分支。
{{< alert type=”note” >}}
如果代码库是公开访问的,则可以在不进行身份验证的情况下访问此端点。
{{< /alert >}}
GET /projects/:id/repository/branches/:branch
参数:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer 或 string | 是 | 项目的 ID 或 URL 编码路径。 |
branch |
string | 是 | 分支的 URL 编码名称。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/repository/branches/main"
示例响应:
{
"name": "main",
"merged": false,
"protected": true,
"default": true,
"developers_can_push": false,
"developers_can_merge": false,
"can_push": true,
"web_url": "https://gitlab.example.com/my-group/my-project/-/tree/main",
"commit": {
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
"short_id": "7b5c3cc",
"created_at": "2012-06-28T03:44:20-07:00",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
],
"title": "add projects API",
"message": "add projects API",
"author_name": "John Smith",
"author_email": "john@example.com",
"authored_date": "2012-06-27T05:51:39-07:00",
"committer_name": "John Smith",
"committer_email": "john@example.com",
"committed_date": "2012-06-28T03:44:20-07:00",
"trailers": {},
"web_url": "https://gitlab.example.com/my-group/my-project/-/commit/7b5c3cc8be40ee161ae89a06bba6229da1032a0c"
}
}
保护代码库分支
有关保护代码库分支的信息,请参阅 POST /projects/:id/protected_branches
。
取消保护代码库分支
有关取消保护代码库分支的信息,请参阅 DELETE /projects/:id/protected_branches/:name
。
创建代码库分支
在代码库中创建一个新分支。
POST /projects/:id/repository/branches
参数:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer | 是 | 项目的 ID 或 URL 编码路径。 |
branch |
string | 是 | 分支名称。 |
ref |
string | 是 | 要从中创建分支的分支名称或提交 SHA。 |
示例请求:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/repository/branches?branch=newbranch&ref=main"
示例响应:
{
"commit": {
"id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c",
"short_id": "7b5c3cc",
"created_at": "2012-06-28T03:44:20-07:00",
"parent_ids": [
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
],
"title": "add projects API",
"message": "add projects API",
"author_name": "John Smith",
"author_email": "john@example.com",
"authored_date": "2012-06-27T05:51:39-07:00",
"committer_name": "John Smith",
"committer_email": "john@example.com",
"committed_date": "2012-06-28T03:44:20-07:00",
"trailers": {},
"web_url": "https://gitlab.example.com/my-group/my-project/-/commit/7b5c3cc8be40ee161ae89a06bba6229da1032a0c"
},
"name": "newbranch",
"merged": false,
"protected": false,
"default": false,
"developers_can_push": false,
"developers_can_merge": false,
"can_push": true,
"web_url": "https://gitlab.example.com/my-group/my-project/-/tree/newbranch"
}
删除代码库分支
从代码库中删除分支。
{{< alert type=”note” >}}
如果出现错误,会提供解释消息。
{{< /alert >}}
DELETE /projects/:id/repository/branches/:branch
参数:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径。 |
branch |
string | 是 | 分支名称。 |
示例请求:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/repository/branches/newbranch"
{{< alert type=”note” >}}
删除分支并不会完全擦除所有相关数据。某些信息仍然存在以保持项目历史记录并支持恢复过程。有关更多信息,请参阅 处理敏感信息。
{{< /alert >}}
删除已合并的分支
删除所有合并到项目默认分支中的分支。
{{< alert type=”note” >}}
受保护分支不会作为此操作的一部分被删除。
{{< /alert >}}
DELETE /projects/:id/repository/merged_branches
参数:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径。 |
示例请求:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/repository/merged_branches"