问题
Are we able to use GitHub API to create a commit? Can we use API to upload a file/blob, like what we can do using Git command, especially in API v4?
回答1:
Presumably yes, using the GitHub Commits API (in the context of a GitHub application)
You can see the all sequence in "GitHub API Git Data":
- Get the current commit object
- Retrieve the tree it points to
- Retrieve the content of the blob object that tree has for that particular file path
- Change the content somehow and post a new blob object with that new content, getting a blob SHA back
- Post a new tree object with that file path pointer replaced with your new blob SHA getting a tree SHA back
- Create a new commit object with the current commit SHA as the parent and the new tree SHA, getting a commit SHA back
- Update the reference of your branch to point to the new commit SHA
Each of those steps has its own GitHub API query.
来源:https://stackoverflow.com/questions/52939328/are-we-able-to-use-github-api-to-create-a-commit-especially-v4