我开始研究主题分支
•-•-• < topic
/
•-• < master
我推动主题分支
$ git push origin topic
其他人将更改推送到主人
•-•-• < origin/topic
/
•-•-•—• < origin/master
历史应该是这样的
•-•-• < topic
/
•-•-•—• < master
; update master
$ git checkout master
$ git fetch origin
$ git merge --ff-only origin/master
; rebase topic
$ git checkout topic
$ git rebase master
topic
上的所有提交都被视为未提交。所以,当我尝试git push origin topic
时,我得到了
! [rejected] topic -> topic (non-fast-forward)
error: failed to push some refs to '/path/to/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
请注意,我不想要将topic
分支与master
合并。我只想更新我的本地仓库,而不必不必要地合并分支。
答案 0 :(得分:9)
为了清楚起见,让我重复你的例子。
C-D-E < topic, origin/topic
/
A-B < master, origin/master
然后有人工作。
C-D-E < topic, origin/topic
/
A-B-F-G < origin/master
^
master
你取得了F&amp; G从起源,然后重新定位主题到主人。所以现在您的存储库看起来像这样。
C-D-E < origin/topic
/
A-B-F-G < master, origin/master
\
C'-D'-E' < topic
这就是问题所在。 E的原点/主题无法快速转发到E'的主题。 Rebase实际上仅适用于未被推送到源的提交。由于您已经将C,D和E推送到源/主题,因此您必须在远程存储库上重写历史记录。因此错误。所以你真的有三个选择:
停止推动局部分支。如果只有你正在研究主题,那么就没有必要推动它了。只需在主人之上保持重新定位主题,完成后,快速将主人合并到主题&amp;推主人。删除本地主题分支。瞧!
合并主题&amp;主。如果你需要在一个主题分支上进行协作,你应该把它搞砸并合并。
强制远程rebase:
git push origin topic -f
这将强制原点/主题为E'。除了在远程存储库中重写历史记录之外,你将拥有火与硫磺,人类牺牲,生活在一起的狗和猫,大规模的歇斯底里......以及你的开发人员并不喜欢你。根本不推荐。
答案 1 :(得分:0)
; update master
git checkout master
git pull --rebase origin master
; rebase topic
git rebase master topic
; push topic (force)
git push -f origin topic
答案 2 :(得分:0)
您的问题存在一些问题。
您的步骤是正确的,除非您忽略了您的rebase已在冲突中停止并且您只是忽略它。您必须解决冲突然后:
git add confilctedfile1.txt conflictedfile2.txt
git rebase --continue
您可能需要为主题分支中的所有提交执行此操作。只有当rebase完成时你才应该推。
另一个注意事项:因此,rebase不是日常工作的首选工作流程。在代码库中发生的事情中,合并更容易,更准确。有很多理由支持合并而不是rebase。