分支下一个分支,如何基于另一个分支? [英] Branch off a branch, How to rebase on another branch?

查看:85
本文介绍了分支下一个分支,如何基于另一个分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在branchB上工作.从branchA分支出来的.几周后,mainline分支开发已经合并了许多提交.分支A和B都落后了.

I started working on branchB. Which was branched off from branchA. After a few weeks, the mainline branch develop have had a lots of commits merged in. Both branches A and B are way behind.

--d1--d2--d3  ...2 weeks later...  --d253  develop
       \
        a1--a2--a3                         branchA
                   \
                    b1--b2--b3             branchB (current)

我想跟上develop分支的最新信息.并且宁愿在最新的提交d253上将我的branchB重新开发为基础.另外,应该忽略所有来自branchA的提交.这将避免我为解决合并冲突(有很多)而付出巨大的努力.因为我不是那个branchA的维护者.我可以在我的branchB中从A重新创建我需要的依赖关系.不确定在重新确定基准之前还是之后应该这样做.

I would like to keep up to date with the develop branch. And prefer to rebase my branchB off develop at its latest commit d253. Also all commits from branchA should be ignored. This will avoid me a huge effort of resolving merge conflicts (there are a lots). Because I am not the maintainer of that branchA. I can recreate in my branchB the dependecies I need from A. Not sure if I should do that before or after the rebase.

--d1--d2--d3  .....  --d253  develop
       \                  \
        a1--a2--a3         \
                            \
                             b1'--b2'--b3'

第一季度.这样做正确吗?

git checkout develop
git pull
git checkout branchB
git rebase --onto develop branchA

第二季度.让我们假设冲突的数量非常重要,大约有30个文件.与git merge develop相比,rebase还是一个好方法吗?

Q2. Let's assume the number of conflicts is quite important, about 30 files. Is rebase still a good approach compared to git merge develop ?

推荐答案

Q1 -是,该命令可以完成您在图片中显示的内容,是的.而且如果分支b与分支a正交,我想很好.我会毫不犹豫地这样做;您是否有理由不希望将两个分支都重新设置为当前的d提交?

Q1 - Well, it is the command that does what you show in the picture, yes. And if branch b is orthogonal to branch a, I suppose that's fine. I would hesitate to do this; is there a reason you don't want to rebase both branches up to a current d commit?

第二季度-我没有注意到rebasemerge在解决冲突方面有很大的不同.最大的不同是,使用您指定的特定基准库,您将不会包含a更改;这意味着,如果a更改与d更改冲突,则无需处理. (如果b更改与a更改重叠,我认为这本身不会引起冲突,但是很可能导致代码处于损坏状态.)

Q2 - I haven't noticed that rebase vs. merge makes much difference in terms of conflict resolution. The big difference would be that with the specific rebase you specified you would not include the a changes; which means if an a change conflicts with a d change you don't have to deal with it. (If a b change overlaps an a change, I don't think this will be noticed as a conflict per se, but it could well result in code in a broken state.)

真正的问题是,b提交是否已与其他开发人员共享?如果是这样,那么通常不建议您重新部署它们,因为这会给其他开发人员带来麻烦.

The real question is, have the b commits been shared with other developers? If so then rebasing them away is not generally recommended as it creates problems for the other developers.

这篇关于分支下一个分支,如何基于另一个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆