简体   繁体   English

Git从多个分支重新建立基础,未获得更改

[英]Git rebase from multiple branches not getting changes

From the master branch I created a branch "topicA" for a project that is just a subset of the original files with a few new files added. 在master分支中,我为项目创建了一个分支“ topicA”,该项目只是原始文件的子集,并添加了一些新文件。 To do this I created the branch, deleted the unneeded files, added some new files and committed. 为此,我创建了分支,删除了不需要的文件,添加了一些新文件并提交了。

I then created a feature branch "topicB" and made some changes. 然后,我创建了一个功能分支“ topicB”并进行了一些更改。

             E--H--I       topicA
            /
           /     K--L--M   topicB
          /     /
A--B--C--D--F--J--N        master

I want the changes in "topicB" to be applied to "topicA". 我希望将“ topicB”中的更改应用于“ topicA”。 The resulting tree would look like: 生成的树看起来像:

                         E--H--I   topicA
                        /
                 K--L--M           topicB
                /
A--B--C--D--F--J--N                master

I've been trying to use rebase for this but have been unable to get the desired result. 我一直在尝试为此使用rebase,但一直无法获得所需的结果。

git checkout topicA
git rebase topicB

This is resulting in a merge and some conflicts I resolved, but not all of the changes from topicB are present in the new topicA. 这导致合并,并且我解决了一些冲突,但是新的topicA中未出现对topicB的所有更改。

I also tried 我也试过

git rebase --onto topicA master topicB

thinking that this would apply the changes from topicB into topicA with master being the common ancestor, but this ended with me being in the topicB branch with changes. 认为这将把主题B的更改应用于主题A,而master是共同的祖先,但这以我在主题B分支中的更改而告终。

After I rebase master with the changes from topicB I would like to then be able to rebase topicA from master to continue to get changes to the files important to topicA. 在用topicB的更改为母版重新设置基础之后,我希望能够从母版中重新设置topicA的基础,以继续获取对topicA重要的文件的更改。

Is it possible to branch from master and then rebase from another branch that was also branched from master? 是否有可能从master分支,然后从也从master分支的另一个分支重新建立基础? Am I using rebase wrong? 我使用rebase错误吗? Would merge be better for this use case? 对于这个用例,合并会更好吗?

Thanks 谢谢

Update The rebase described by @VonC works and now I have a tree like: 更新 @VonC描述的rebase有效,现在我有了像这样的树:

                         E--H--I   topicA
                        /
                 K--L--M--O        topicB
                /
A--B--C--D--F--J--N                master

When I try to rebase topicA from topicB again to get the new change I ran 当我尝试再次从topicB重新设置topicA以获得新更改时,

git checkout topicA
git rebase topicB

But it is asking me to resolve conflicts I've already resolved to rebase topicA and get it branched off of M. How do rebase topicA to topicB 'O' without dealing with all of the conflicts I've already resolved? 但这是要我解决我已经解决的将主题A重新设置为基准并使它从M分支出来的冲突。如何在不处理我已经解决的所有冲突的情况下将主题A重新设置为主题B'O'?

The rebase --onto should use the exact commit from which topicA was created: rebase --onto应该使用topicA创建topicA的确切提交:

git rebase --onto topicB D topicA

See that example for illustration. 请参见该示例以获取说明。

That would get: 那会得到:

                         E'--H'--I'   topicA
                        /
                 K--L--M              topicB
                /  
A--B--C--D--F--J--N                   master

Then, yes, you can rebase topicA on top of master : 然后,是的,您可以将topicA设置为master

 git checkout topicA
 git rebase master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM