Git 트리에 대한 REST API 엔드포인트
REST API를 사용하여 GitHub Enterprise Cloud에서 Git 데이터베이스 트리 개체와 상호 작용합니다.
Git 트리 정보
Git 트리 개체는 Git 리포지토리의 파일 간에 계층 구조를 만듭니다. Git 트리 개체를 사용하여 디렉터리와 디렉터리에 포함된 파일 간의 관계를 만들 수 있습니다. 해당 엔드포인트를 사용하면 GitHub Enterprise Cloud에서 Git 데이터베이스에 트리 개체를 읽고 쓸 수 있습니다.
Create a tree
The tree creation API accepts nested entries. If you specify both a tree and a nested path modifying that tree, this endpoint will overwrite the contents of the tree with the new path contents, and create a new tree structure.
If you use this endpoint to add, delete, or modify the file contents in a tree, you will need to commit the tree and then update a branch to point to the commit. For more information see "Create a commit" and "Update a reference."
Returns an error if you try to delete a file that does not exist.
"Create a tree"에 대한 세분화된 액세스 토큰
이 엔드포인트는 다음 세분화된 토큰 형식에서 작동합니다.:
세분화된 토큰에는 다음 권한 집합이 있어야 합니다.:
- "Contents" repository permissions (write)
"Create a tree"에 대한 매개 변수
속성, 형식, 설명 |
---|
accept string Setting to |
속성, 형식, 설명 |
---|
owner string RequiredThe account owner of the repository. The name is not case sensitive. |
repo string RequiredThe name of the repository without the |
속성, 형식, 설명 | ||||||
---|---|---|---|---|---|---|
tree array of objects RequiredObjects (of | ||||||
Properties of |
속성, 형식, 설명 |
---|
path string The file referenced in the tree. |
mode string The file mode; one of 다음 중 하나일 수 있습니다.: |
type string Either 다음 중 하나일 수 있습니다.: |
sha string or null The SHA1 checksum ID of the object in the tree. Also called Note: Use either |
content string The content you want this file to have. GitHub will write this blob out and use that SHA for this entry. Use either this, or Note: Use either |
base_tree
string The SHA1 of an existing Git tree object which will be used as the base for the new tree. If provided, a new Git tree object will be created from entries in the Git tree object pointed to by base_tree
and entries defined in the tree
parameter. Entries defined in the tree
parameter will overwrite items from base_tree
with the same path
. If you're creating new changes on a branch, then normally you'd set base_tree
to the SHA1 of the Git tree object of the current latest commit on the branch you're working on.
If not provided, GitHub will create a new Git tree object from only the entries defined in the tree
parameter. If you create a new commit pointing to such a tree, then all files which were a part of the parent commit's tree and were not defined in the tree
parameter will be listed as deleted by the new commit.
"Create a tree"에 대한 HTTP 응답 상태 코드
상태 코드 | 설명 |
---|---|
201 | Created |
403 | Forbidden |
404 | Resource not found |
409 | Conflict |
422 | Validation failed, or the endpoint has been spammed. |
"Create a tree"에 대한 코드 샘플
If you access GitHub at GHE.com, replace api.github.com
with your enterprise's dedicated subdomain at api.SUBDOMAIN.ghe.com
.
요청 예제
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/git/trees \
-d '{"base_tree":"9fb037999f264ba9a7fc6274d15fa3ae2ab98312","tree":[{"path":"file.rb","mode":"100644","type":"blob","sha":"44b4fc6d56897b048c772eb4087f854f46256132"}]}'
Response
Status: 201
{
"sha": "cd8274d15fa3ae2ab983129fb037999f264ba9a7",
"url": "https://api.github.com/repos/octocat/Hello-World/trees/cd8274d15fa3ae2ab983129fb037999f264ba9a7",
"tree": [
{
"path": "file.rb",
"mode": "100644",
"type": "blob",
"size": 132,
"sha": "7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b",
"url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/7c258a9869f33c1e1e1f74fbb32f07c86cb5a75b"
}
],
"truncated": true
}
Get a tree
Returns a single tree using the SHA1 value or ref name for that tree.
If truncated
is true
in the response then the number of items in the tree
array exceeded our maximum limit. If you need to fetch more items, use the non-recursive method of fetching trees, and fetch one sub-tree at a time.
Note
The limit for the tree
array is 100,000 entries with a maximum size of 7 MB when using the recursive
parameter.
"Get a tree"에 대한 세분화된 액세스 토큰
이 엔드포인트는 다음 세분화된 토큰 형식에서 작동합니다.:
세분화된 토큰에는 다음 권한 집합이 있어야 합니다.:
- "Contents" repository permissions (read)
공용 리소스만 요청되는 경우 인증 또는 앞서 언급한 권한 없이 이 엔드포인트를 사용할 수 있습니다.
"Get a tree"에 대한 매개 변수
속성, 형식, 설명 |
---|
accept string Setting to |
속성, 형식, 설명 |
---|
owner string RequiredThe account owner of the repository. The name is not case sensitive. |
repo string RequiredThe name of the repository without the |
tree_sha string RequiredThe SHA1 value or ref (branch or tag) name of the tree. |
속성, 형식, 설명 |
---|
recursive string Setting this parameter to any value returns the objects or subtrees referenced by the tree specified in |
"Get a tree"에 대한 HTTP 응답 상태 코드
상태 코드 | 설명 |
---|---|
200 | OK |
404 | Resource not found |
409 | Conflict |
422 | Validation failed, or the endpoint has been spammed. |
"Get a tree"에 대한 코드 샘플
If you access GitHub at GHE.com, replace api.github.com
with your enterprise's dedicated subdomain at api.SUBDOMAIN.ghe.com
.
요청 예제
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/git/trees/TREE_SHA
Default response
Status: 200
{
"sha": "9fb037999f264ba9a7fc6274d15fa3ae2ab98312",
"url": "https://api.github.com/repos/octocat/Hello-World/trees/9fb037999f264ba9a7fc6274d15fa3ae2ab98312",
"tree": [
{
"path": "file.rb",
"mode": "100644",
"type": "blob",
"size": 30,
"sha": "44b4fc6d56897b048c772eb4087f854f46256132",
"url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/44b4fc6d56897b048c772eb4087f854f46256132"
},
{
"path": "subdir",
"mode": "040000",
"type": "tree",
"sha": "f484d249c660418515fb01c2b9662073663c242e",
"url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/f484d249c660418515fb01c2b9662073663c242e"
},
{
"path": "exec_file",
"mode": "100755",
"type": "blob",
"size": 75,
"sha": "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/45b983be36b73c0788dc9cbcb76cbb80fc7bb057"
}
],
"truncated": false
}