我想从masterinto中拉入较新的提交topic,但不是以topic在 之上重放更改的方式,master反之亦然。我希望新的更改在master上播放topic,并将结果安装为新的topic头。
如果我变基master到topic,我可以得到完全正确的对象,唯一的问题是该对象被安装为master而不是的新头topic。
有没有一些不错的方法可以做到这一点,而无需手动改组临时头指针?
编辑:
下面是如何使用临时分支头来实现它,但它很笨拙:
git checkout master
git checkout -b temp # temp points to master
git rebase topic # topic is brought into temp, temp changes played on top
现在我们有了我们想要的对象,它被 指向了temp。
git checkout topic
git reset --hard temp
现在topic有了;剩下的就是通过删除 temp 来整理:
git branch -d temp
另一种方法是取消temp并只是变基master,然后重置topic为master. master最后,通过从 reflog 或剪切粘贴缓冲区中拉出它的旧头来重置它原来的样子。这使它归结为六个步骤,仍然很尴尬:
git checkout master
git rebase topic # solve conflicts, git rebase --continue, if necessary
git checkout topic
git reset --hard master # topic and master same now
git checkout master
git reset --hard HEAD@{13}
最好在最后一步依赖一些保存的提交哈希,而不是通过 reflog 进行搜索。
为什么这很有用
假设您有一些人在分支上工作,他们正在协作进行一些master与 . 通过这种方式进行变基,我们可以避免分支上的非快进更改(重写分支历史)。master在将分支整合到其中时如何处理是另一回事;但是有一些选项,包括避免对master.