拉取请求时如何返回到提交

时间:2020-04-21 12:42:00

标签: git github commit pull-request

发出请求,然后无意中进行了一些额外的提交,并且无法返回到分支中的第一次提交。

我做什么:

git reset HEAD@{10}
git add .
git commit --amend --no-edit
git push origin areaSelection

错误:

To https://github.com/YaroshenkoYaroslav/WorldEdit.git
 ! [rejected]        areaSelection -> areaSelection (non-fast-forward)
error: failed to push some refs to 'https://github.com/YaroshenkoYaroslav/WorldEdit.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我该如何解决?

1 个答案:

答案 0 :(得分:1)

您有两个选择,这可能仅取决于团队中的约定或对github存储库的限制。

  1. 推送的内容不应更改;因此只需在远程分支的顶部创建一个新的提交,然后将其推送即可。
  2. 您真的要重写分支的历史记录。这意味着之前推送的某些引用将消失(您删除的提交)。在这种情况下,您需要强制执行以下操作:git push --force-with-lease