git - GithubAPI 提交没有快进
问题描述
因为有些日子我尝试与 GitHub API 交互以创建提交。我的问题是 GIT 中的结果,在对新提交的引用更新之后。Github 每次都会返回:
Status Code 422: {
"message": "Update is not a fast forward",
"documentation_url": "https://docs.github.com/enterprise/2.22/rest/reference/git#update-a-reference"
}
但我不想在主分支上创建一个快进提交,只是一个新的提交。我忘记了哪个参数或者我设置了错误?
为了重现我使用邮递员的错误:
- 创建 Blob - https://{{server}}/api/v3/repos/:owner/:repo/git/blob
{
"content":"This is my content at {{currentDate}}",
"encoding":"utf-8"
}
-> 将 response.sha 保存在“shaBlob”中。
2. getRef - https://{{server}}/api/v3/repos/:owner/:repo/git/ref/heads/master
-> 将 response.object.sha 保存在“shaMaster”中。
3. getLastCommit - https://{{server}}/api/v3/repos/:owner/:repo/git/commits/:commit_sha
-> 在“shaMasterTree”中保存 response.tree.sha
4. 创建树 - https ://{{server}}/api/v3/repos/:owner/:repo/git/trees
正文:
{
"base_tree": "{{shaCommitLast}}",
"tree": [{
"path": "readme.md",
"mode": "100644",
"type": "blob",
"sha": "{{shaBlob}}"
}]
}
-> 在 shaTreeNew 中保存 response.sha
5. 创建提交 - https://{{server}}/api/v3/repos/:owner/:repo/git/commits 正文:
{
"message": "This is a bot Commit",
"tree": "{{shaTreeNew}}",
"author": {
"name": "ASLob",
"email": "aslob@mydomain.com",
"date": "{{currentDate}}"
},
"committer": {
"name": "ASLob",
"email": "aslob@mydomain.com",
"date": "{{currentDate}}"
}
}
-> 在 shaCommitNew 中保存 response.sha 6. 更新参考 - https://{{server}}/api/v3/repos/:owner/:repo/git/refs/:ref 正文:
{
"sha": "{{shaCommitNew}}",
"force": false
}
解决方案
推荐阅读
- javascript - 检查对象数组是否包含对象
- javascript - Firestore 规则:通过 threadId 以安全的方式获取消息线程
- jenkins - 如何获取可以通过API登录jenkins的用户列表
- c++ - 为什么我可以在编译时评估接收 std::pair 的函数,但不能断言它?
- javascript - 网站如何跟踪用户在推荐页面上花费的时间?
- php - 通过连接调用 PHP 函数
- javascript - 滚动到每个循环滚动到错误部分的部分
- javascript - Laravel Ajax 更新几个选择
- python - 如何在括号之间返回字符串
- python-3.x - 使用 Python3 检查 FTP 上是否存在目录