Git rebase from multiple branches not getting changes

匆匆过客 提交于 2020-01-03 03:46:05

问题


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. 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.

             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". 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.

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.

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.

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.

Is it possible to branch from master and then rebase from another branch that was also branched from master? Am I using rebase wrong? Would merge be better for this use case?

Thanks

Update The rebase described by @VonC works and now I have a tree like:

                         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

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?


回答1:


The rebase --onto should use the exact commit from which topicA was created:

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:

 git checkout topicA
 git rebase master


来源:https://stackoverflow.com/questions/23646765/git-rebase-from-multiple-branches-not-getting-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!