根据每个提交的日期,两个分支如何组合成一个分支? [英] How can two branches be combined into a single branch based on the date of each commit?

查看:199
本文介绍了根据每个提交的日期,两个分支如何组合成一个分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个git仓库,如下所示:

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


为了使事情变得更简单,我们假设branchA上的提交是对fileA的严格修改,对branchB的提交是严格的修改fileB。



我想将这些分支组合到第三个分支branchAB,其中提交将按日期排序:

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

有没有办法使用一个git命令自动执行此操作,或者我坚持手动方法(例如樱桃采摘或rebase -i)?



BTW, merge-base 是一个标签。 / p>

决方案

这是一个解决方案,根据 adymitruk的原始答案

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


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.

解决方案

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

这篇关于根据每个提交的日期,两个分支如何组合成一个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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