Are we able to use GitHub API to create a commit? especially v4?

浪子不回头ぞ 提交于 2019-12-08 04:48:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!