GitHub API - 写入存储库 [英] GitHub API - write to repo
问题描述
我查看了所有文档,但没有回答我的问题.
I looked all documentation, but it doesn't answer my question.
有没有办法写入存储库(上传文件)?像创建一个文件夹,并上传一个 readme.md
There is a way to write to a repo (upload a file)? Something like create a folder, and upload a readme.md
推荐答案
文件夹不需要创建,因为它们仅隐式存在于 git 中.这意味着如果您有一个路径为 folder/file.txt
的文件,那么您的 git 客户端知道创建一个名为folder"的文件夹.其中文件file.txt"已保存,但对于 git 来说,它只是一个名为folder/file.txt"的文件
Folders do not need to be created as they only exists implicitly in git. Meaning that if you have a file with path folder/file.txt
then your git client knows to create a folder called "folder" where the file "file.txt" is saved, but to git it is just a file with the name "folder/file.txt"
您可以使用: PUT/repos/{owner}/{repo}/contents/{path}
其中 {path}
是文件夹路径和文件名,并将消息和文件内容(Base64 编码)放入正文.
You can use: PUT /repos/{owner}/{repo}/contents/{path}
where {path}
is the folder path and file name, and put message and file content (Base64 encoded) in the body.
在更新文件时,您还需要在文件的 git 历史记录中指明要更新的版本.在这里阅读更多https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents
When you are updating a file you also need to indicate which version in the git history of the file you want to update. Read more here https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents
这篇关于GitHub API - 写入存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!