Эта версия GitHub Enterprise Server была прекращена 2024-03-26. Исправления выпускаться не будут даже при критических проблемах безопасности. Для повышения производительности, повышения безопасности и новых функций выполните обновление до последней версии GitHub Enterprise Server. Чтобы получить справку по обновлению, обратитесь в службу поддержки GitHub Enterprise.
Конечные точки REST API для ссылок на Git
Использование REST API для взаимодействия со ссылками в базе данных Git на GitHub Enterprise Server
Сведения о ссылках на Git
Ссылка на Git (git ref
) — это файл, содержащий хэш SHA-1 фиксации Git. При ссылке на фиксацию Git можно использовать ссылку Git, которая представляет собой простое запоминающееся имя, а не хэш. Ссылку на Git можно перезаписать, чтобы указать на новую фиксацию. Ветвь — это ссылка на Git, в которой хранится новый хэш фиксации Git. Эти конечные точки позволяют считывать и записывать ссылки на базу данных Git в GitHub Enterprise Server.
List matching references
Returns an array of references from your Git database that match the supplied name. The :ref
in the URL must be formatted as heads/<branch name>
for branches and tags/<tag name>
for tags. If the :ref
doesn't exist in the repository, but existing refs start with :ref
, they will be returned as an array.
When you use this endpoint without providing a :ref
, it will return an array of all the references from your Git database, including notes and stashes if they exist on the server. Anything in the namespace is returned, not just heads
and tags
.
Note: You need to explicitly request a pull request to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "Checking mergeability of pull requests".
If you request matching references for a branch named feature
but the branch feature
doesn't exist, the response can still include other matching head refs that start with the word feature
, such as featureA
and featureB
.
Параметры для "List matching references"
Имя., Тип, Description |
---|
accept string Setting to |
Имя., Тип, Description |
---|
owner string Обязательное полеThe account owner of the repository. The name is not case sensitive. |
repo string Обязательное полеThe name of the repository without the |
ref string Обязательное полеThe Git reference. For more information, see "Git References" in the Git documentation. |
Коды состояния http-ответа для "List matching references"
Код состояния | Описание |
---|---|
200 | OK |
409 | Conflict |
Примеры кода для "List matching references"
Пример запроса
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/matching-refs/REF
Response
Status: 200
[
{
"ref": "refs/heads/feature-a",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlLWE=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/refs/heads/feature-a",
"object": {
"type": "commit",
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
}
},
{
"ref": "refs/heads/feature-b",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlLWI=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/refs/heads/feature-b",
"object": {
"type": "commit",
"sha": "612077ae6dffb4d2fbd8ce0cccaa58893b07b5ac",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/commits/612077ae6dffb4d2fbd8ce0cccaa58893b07b5ac"
}
}
]
Get a reference
Returns a single reference from your Git database. The :ref
in the URL must be formatted as heads/<branch name>
for branches and tags/<tag name>
for tags. If the :ref
doesn't match an existing ref, a 404
is returned.
Note: You need to explicitly request a pull request to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "Checking mergeability of pull requests".
Параметры для "Get a reference"
Имя., Тип, Description |
---|
accept string Setting to |
Имя., Тип, Description |
---|
owner string Обязательное полеThe account owner of the repository. The name is not case sensitive. |
repo string Обязательное полеThe name of the repository without the |
ref string Обязательное полеThe Git reference. For more information, see "Git References" in the Git documentation. |
Коды состояния http-ответа для "Get a reference"
Код состояния | Описание |
---|---|
200 | OK |
404 | Resource not found |
409 | Conflict |
Примеры кода для "Get a reference"
Пример запроса
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/ref/REF
Response
Status: 200
{
"ref": "refs/heads/featureA",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlQQ==",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/refs/heads/featureA",
"object": {
"type": "commit",
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
}
}
Create a reference
Creates a reference for your repository. You are unable to create new references for empty repositories, even if the commit SHA-1 hash used exists. Empty repositories are repositories without branches.
Параметры для "Create a reference"
Имя., Тип, Description |
---|
accept string Setting to |
Имя., Тип, Description |
---|
owner string Обязательное полеThe account owner of the repository. The name is not case sensitive. |
repo string Обязательное полеThe name of the repository without the |
Имя., Тип, Description |
---|
ref string Обязательное полеThe name of the fully qualified reference (ie: |
sha string Обязательное полеThe SHA1 value for this reference. |
Коды состояния http-ответа для "Create a reference"
Код состояния | Описание |
---|---|
201 | Created |
409 | Conflict |
422 | Validation failed, or the endpoint has been spammed. |
Примеры кода для "Create a reference"
Пример запроса
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/refs \
-d '{"ref":"refs/heads/featureA","sha":"aa218f56b14c9653891f9e74264a383fa43fefbd"}'
Response
Status: 201
{
"ref": "refs/heads/featureA",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlQQ==",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/refs/heads/featureA",
"object": {
"type": "commit",
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
}
}
Update a reference
Updates the provided reference to point to a new SHA. For more information, see "Git References" in the Git documentation.
Параметры для "Update a reference"
Имя., Тип, Description |
---|
accept string Setting to |
Имя., Тип, Description |
---|
owner string Обязательное полеThe account owner of the repository. The name is not case sensitive. |
repo string Обязательное полеThe name of the repository without the |
ref string Обязательное полеThe Git reference. For more information, see "Git References" in the Git documentation. |
Имя., Тип, Description |
---|
sha string Обязательное полеThe SHA1 value to set this reference to |
force boolean Indicates whether to force the update or to make sure the update is a fast-forward update. Leaving this out or setting it to По умолчанию.: |
Коды состояния http-ответа для "Update a reference"
Код состояния | Описание |
---|---|
200 | OK |
409 | Conflict |
422 | Validation failed, or the endpoint has been spammed. |
Примеры кода для "Update a reference"
Пример запроса
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/refs/REF \
-d '{"sha":"aa218f56b14c9653891f9e74264a383fa43fefbd","force":true}'
Response
Status: 200
{
"ref": "refs/heads/featureA",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlQQ==",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/refs/heads/featureA",
"object": {
"type": "commit",
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
"url": "https://HOSTNAME/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
}
}
Delete a reference
Deletes the provided reference.
Параметры для "Delete a reference"
Имя., Тип, Description |
---|
accept string Setting to |
Имя., Тип, Description |
---|
owner string Обязательное полеThe account owner of the repository. The name is not case sensitive. |
repo string Обязательное полеThe name of the repository without the |
ref string Обязательное полеThe Git reference. For more information, see "Git References" in the Git documentation. |
Коды состояния http-ответа для "Delete a reference"
Код состояния | Описание |
---|---|
204 | No Content |
409 | Conflict |
422 | Validation failed, or the endpoint has been spammed. |
Примеры кода для "Delete a reference"
Пример запроса
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/refs/REF
Response
Status: 204