此版本的 GitHub Enterprise 已停止服务 2022-10-12. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持。
Git � �
通过Git � � API,可以在 GitHub Enterprise Server 上读取� �对象并将其写入 Git 数据库。
关于 Git � � API
Git � �对象在 Git 仓库中的文件之间创建层次结构。 您可以使用 Git � �对象创建目录与其包含的文件之间的关系。 通过这些终结点,可以在 GitHub Enterprise Server 上读取� �对象并将其写入 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.
参数
Headers | |||||||||
---|---|---|---|---|---|---|---|---|---|
Name, Type, Description | |||||||||
accept stringSetting to | |||||||||
Path parameters | |||||||||
Name, Type, Description | |||||||||
owner stringRequiredThe account owner of the repository. The name is not case sensitive. | |||||||||
repo stringRequiredThe name of the repository. The name is not case sensitive. | |||||||||
Body parameters | |||||||||
Name, Type, Description | |||||||||
tree array of objectsRequiredObjects (of | |||||||||
Properties of tree
| |||||||||
base_tree stringThe 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 |
HTTP 响应状态代� �
状态代� � | 说明 |
---|---|
201 | Created |
403 | Forbidden |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
代� �示例
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/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 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.
参数
Headers |
---|
Name, Type, Description |
accept stringSetting to |
Path parameters |
Name, Type, Description |
owner stringRequiredThe account owner of the repository. The name is not case sensitive. |
repo stringRequiredThe name of the repository. The name is not case sensitive. |
tree_sha stringRequired |
Query parameters |
Name, Type, Description |
recursive stringSetting this parameter to any value returns the objects or subtrees referenced by the tree specified in |
HTTP 响应状态代� �
状态代� � | 说明 |
---|---|
200 | OK |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
代� �示例
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/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
}