Esta versão do GitHub Enterprise foi descontinuada em 2022-06-03. Nenhum lançamento de patch será feito, mesmo para questões críticas de segurança. Para obter melhor desempenho, melhorar a segurança e novos recursos, upgrade to the latest version of GitHub Enterprise. Para ajuda com a atualização, contact GitHub Enterprise support.
Árvores do Git
A API de árvores do Git permite que você leia e escreva objetos em seu banco de dados Git em GitHub Enterprise Server.
Sobre a API de árvores do Git
Um objeto da árvore do Git cria a hierarquia entre arquivos em um repositório do Git. Você pode usar o objeto da árvore do Git para criar a relação entre diretórios e os arquivos que eles contêm. Estes pontos de extremidade permitem que você leia e escreva objetos de árvore em seu banco de dados do Git em GitHub Enterprise Server.
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."
Parâmetros
Headers | |||||||||
---|---|---|---|---|---|---|---|---|---|
Nome, Tipo, Descrição | |||||||||
accept stringSetting to | |||||||||
Path parameters | |||||||||
Nome, Tipo, Descrição | |||||||||
owner stringObrigatórioThe account owner of the repository. The name is not case sensitive. | |||||||||
repo stringObrigatórioThe name of the repository. The name is not case sensitive. | |||||||||
Body parameters | |||||||||
Nome, Tipo, Descrição | |||||||||
tree array of objectsObrigatórioObjects (of | |||||||||
Properties of the |
Nome, Tipo, Descrição |
---|
path stringThe file referenced in the tree. |
mode stringThe file mode; one of Pode ser uma das ações a seguir: |
type stringEither Pode ser uma das ações a seguir: |
sha string or nullThe SHA1 checksum ID of the object in the tree. Also called Note: Use either |
content stringThe 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
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 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.
HTTP response status codes
Status code | Descrição |
---|---|
201 | Created |
403 | Forbidden |
404 | Resource not found |
422 | Validation failed |
Amostras de código
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <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.
Parâmetros
Headers |
---|
Nome, Tipo, Descrição |
accept stringSetting to |
Path parameters |
Nome, Tipo, Descrição |
owner stringObrigatórioThe account owner of the repository. The name is not case sensitive. |
repo stringObrigatórioThe name of the repository. The name is not case sensitive. |
tree_sha stringObrigatório |
Parâmetros de consulta |
Nome, Tipo, Descrição |
recursive stringSetting this parameter to any value returns the objects or subtrees referenced by the tree specified in |
HTTP response status codes
Status code | Descrição |
---|---|
200 | OK |
404 | Resource not found |
422 | Validation failed |
Amostras de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <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
}