【问题标题】:Merging selected files from similar branches after one was rebased在一个被重新定位后合并来自相似分支的选定文件
【发布时间】:2016-01-04 02:01:24
【问题描述】:

当我在处理feature1 时,在下面的提交点A,我被要求在其上构建另一个mod。我们称之为feature1+。这意味着图表如下所示:

master: o---o---o---o---o
             \
feature1:     o---e---e---e---O---A
                                   \
feature1+:                          o---c---c---X

现在我想将feature1+ 合并回feature1,但我意识到XA 中存在的文件之间的更改很小; c 提交中有两个新的跟踪文件。

在此过程中,我开始整合feature1 上的提交,将e 提交重新设置为一个o' 以减少最后返回到master 上的提交数量。我相信有效的图表是这样的:

master: o---o---o---o---o
             \
feature1:     o---o'---O---A
               \     
feature1+:      o---e---e---e---O---A---c---c---X

但是,这意味着feature1+ 在我运行时也会将e 提交转储到feature1

git checkout feature1
git merge feature1+

这给了我:

master: o---o---o---o---o
             \
feature1:     o---o'---O---A---e---e---e---O---c---c---X

我想在不重新引入 e 的情况下添加 c 提交。换句话说,将它合并回这个:

master: o---o---o---o---o
             \
feature1:     o---o'---O---A---c---c---X

我该怎么做?我尝试在 A 的 feature1 中仅 checkout 来自 c 的新文件,但当然这会提供文件而不保留其历史记录。

【问题讨论】:

    标签: git merge rebase


    【解决方案1】:

    在分店时:feature1 在 A 签出:

    执行git cherry-pick feature1+: A .. X 应该会生成所需的树

    master: o---o---o---o---o
                 \
    feature1:     o---o'---O---A---c---c---X
    

    【讨论】:

      【解决方案2】:

      @nevyn 在 Freenode IRC 的#git 频道上建议的最短答案是 cherry-pick 所需的提交到 feature1(文档建议这样做,但我可能只是不敢尝试):

      git checkout feature1
      git cherry-pick c # the first c
      git cherry-pick c # OK, the second one, I didn't think ahead THAT far.
      git branch -d feature1+ # warns + gives the correct command for an unmerged branch
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-07
        • 2014-04-30
        • 2012-08-23
        • 1970-01-01
        • 2022-11-09
        相关资源
        最近更新 更多