【问题标题】:Move multiple non-consecutive commits to different branch将多个非连续提交移动到不同的分支
【发布时间】:2016-07-29 09:09:39
【问题描述】:

我有两个不应该直接合并在一起的分支(还)。但是,我需要将两个不同的非连续提交从一个分支移动到另一个分支。我目前有:

top-branch:
A-B-C-D

bottom-branch:
X-Y

我想得到:

top-branch:
A-C

bottom-branch:
X-Y-B-D

【问题讨论】:

    标签: git git-branch git-rebase


    【解决方案1】:

    假设你从一个类似的情况开始:

    > git log --oneline --graph --all --decorate=short
    * e08a53c (HEAD, bottom-branch) Y
    * b659a43 X
    | * 88612b2 (top-branch) D
    | * 8b37e26 C
    | * afe4ffd B
    | * 5bc157c A
    |/
    * e3c7a2d other commit
    

    我会从分支bottom-branchcherry-picking 你需要的两个提交开始

    git cherry-pick afe4ffd
    

    然后回到 top-branch 和交互式 rebase 以删除您不需要的两个提交

    git rebase -i HEAD~4
    

    【讨论】:

    • 这正是我最终要做的。我以前不知道git cherry-pick
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 2011-07-25
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 2019-02-16
    相关资源
    最近更新 更多