开发者

GitHub API - write to repo

开发者 https://www.devze.com 2023-03-20 06:17 出处:网络
I looked all documentatio开发者_如何学Pythonn, but it doesn\'t answer my question. There is a way to write to a repo (upload a file)? Something like create a folder, and upload a readme.mdFolders do n

I looked all documentatio开发者_如何学Pythonn, but it doesn't answer my question.

There is a way to write to a repo (upload a file)? Something like create a folder, and upload a readme.md


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"

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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消