【问题标题】:Splitting git history into branches将 git 历史拆分为分支
【发布时间】:2018-03-11 16:11:05
【问题描述】:

我们使用 Git 进行回购。我不知道是怎么回事,但我的团队的最新历史是这样结束的:

0                 master
 \
  1-2-3-4-5-6-7   branch1 & branch2

请注意(谢天谢地)没有人将它与我们的主分支合并。现在,我想把它拆分成这样:

             5-6-7     branch2
            /     \
0  - - -  (*) - - (*)  master
 \       /  
  1-2-3-4              branch1

我没有使用 Git 的经验,我想知道如何实现这一点

【问题讨论】:

    标签: git split branch revision-history


    【解决方案1】:

    假设branch1branch2 都指向7,更安全的选择是创建另一个分支n_branch1 并执行以下操作:

    git checkout <sha_4>
    # you'll now be in a detached head
    git checkout -b n_branch1   
    # Now go to master and merge n_branch1
    git checkout master
    git merge n_branch1
    # Once branch1 commits are merged, apply branch2 on top of them.
    git checkout branch2
    git rebase master
    

    注意:您还可以通过将 branch1 还原为 4 来重复使用它(请参阅 here)。

    【讨论】:

    • 我最终接受了您的第二个想法,即通过恢复为 4 来重用 branch1。谢谢!
    猜你喜欢
    • 2015-07-24
    • 1970-01-01
    • 2021-09-03
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    相关资源
    最近更新 更多