问题
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