我已经fork了一个github仓库,我的fork现在比原始仓库超前几个提交。现在,我想将这些提交中的一个作为PR提供给原始仓库。
按照这个问题的答案所述,我执行了以下操作:
git remote add official [URL to original repo]
git checkout -b hotfix-for-feature official/master
git cherry-pick [feature-hash]
git push -u origin hotfix-for-feature
结果是我得到了:
! [rejected] hotfix-for-feature -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/myusername/repositoryname'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
请注意以下几点:
- 在执行
git push -u
时,分支参数会被完全忽略,它会推送到origin/master。 origin/hotfix-for-feature
和official/hotfix-for-feature
都不存在于远程仓库中。official/master
没有做任何更新——我刚刚才拉取过。
如果尝试使用git branch hotfix-for-feature --set-upstream=origin/hotfix-for-feature
命令,则会提示应该使用git push -u
来实现。 如果尝试使用git push -u origin/hotfix-for-feature
命令,则会得到以下提示:
fatal: You are pushing to remote 'origin/hotfix-for-feature',
which is not the upstream of your current branch 'hotfix-for-feature',
without telling me what to push to update which remote branch.
除了作为如何不编写错误消息的良好示例外,我不理解"which"。我指定要推送的内容(当前分支)和要更新的远程分支。
我发现有很多关于此错误的问题,但通常是关于某个远程分支领先于本地分支,在这种情况下没有现有的远程分支。此外,“pushed branch”和“remote [branch]”之间有什么区别?
git push -u origin hotfix-for-feature:hotfix-for-feature
。 - dan1st