
php小编小新在使用go-github时,遇到了一个问题:在创建提交时,出现了422错误,并且提示“更新不是快进”。这个问题的具体原因是什么呢?该如何解决呢?接下来,我们将为大家详细解答。
我使用以下函数简单地使用 go-github 库在分支中创建一个新提交
func ghapicreatecommit(ctx context.context, client *github.client, commitopts *commitoptions) error {
// get the reference of the branch
ref, _, err := client.git.getref(ctx, repoowner, commitopts.repo, "refs/heads/"+commitopts.branch)
if err != nil {
return err
}
commit, _, err := client.git.getcommit(ctx, repoowner, commitopts.repo, *ref.object.sha)
if err != nil {
return err
}
commit.message = github.string(commitopts.commitmessage)
// create a new commit with the updated commit message
newcommit, _, err := client.git.createcommit(ctx, repoowner, commitopts.repo, commit)
if err != nil {
return err
}
// attach the new commit to the reference
ref.object.sha = newcommit.sha
// update the branch reference to point to the new commit
_, _, err = client.git.updateref(ctx, repoowner, commitopts.repo, ref, false)
if err != nil {
return err
}
return nil
}
此操作失败:
PATCH https://api.github.com/repos/MyOrg/myrepo/git/refs/heads/the-branch-I-am-creating-the-new-commit-to: 422 Update is not a fast forward []
为什么不快进?它只是从现有分支/提交创建的新提交。
ps:我明确不想想要在提交时创建新文件。
Sveil开源商城是专业和创新的开源在线购物车的解决方案,是基于osCommerce 3 alpha 5 独立开发的项目。环境为PHP+MYSQL,使用了先进的AJAX技术和富互联网应用(RIA)的框架ExtJS,由Sveil.com提供重要的可用性改善及与网站交互界面速度更快,更高效。VERSION 1.0--修复bug1、网站在维护2、当搜索引擎被激活,与我们联系功能不起作用。3、当SEO被激
6
func (s *gitservice) createcommit(ctx context.context, owner string, repo string, commit *commit) (*commit, *response, error)
参数commit用于指定新commit的一些信息,包括新commit的parents(参见实现)。
在您的代码中,新提交和旧提交具有相同的 parents,因此这不是快进推送到分支。为了使其快速推送到分支,新提交的 parents 应指向旧提交。
我想以下更改会使其快进:
+ commit.Parents = []*github.Commit{commit}
newCommit, _, err := client.Git.CreateCommit(ctx, repoOwner, commitOpts.Repo, commit)以上就是无法使用 go-github 和 422 创建提交 - 更新不是快进的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号