How can two branches be combined into a single branch based on the date of each commit?

二次信任 提交于 2019-12-06 05:52:33

问题


Let's say I have a git repository that looks like this:

merge-base---A1--A2------A3------A4 (branchA)
          \
           ----------B1------B2 (branchB)

To make things simpler, let's say the commits on branchA are strictly modifications to fileA, and the commits on branchB are strictly modifications to fileB.

I want to combine these branches into a third branch, branchAB, where the commits will be ordered by date:

merge-base---A1--A2------A3------A4 (branchA)
          \
           ----------B1------B2 (branchB)
            \
             A1--A2--B1--A3--B2--A4 (branchAB)

Is there a way to automatically do this with a single git command, or am I stuck with manual methods (e.g. cherry picking or rebase -i)?

BTW, merge-base is a tag.


回答1:


Here's a solution that does what I want, based on adymitruk's original answer:

git checkout -b branchAB merge-base
git merge branchA
git merge branchB
git rebase --onto merge-base merge-base branchAB



回答2:


This should do it:

git branch branchAB branchA
git checkout branchB
git merge branchA
git rebase --onto A1^ B1^ branchAB

The rebase will "eat" the merge commit as --preserve-merges was not specified.

hope this helps



来源:https://stackoverflow.com/questions/5410742/how-can-two-branches-be-combined-into-a-single-branch-based-on-the-date-of-each

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