【问题标题】:Apply range of commits from one branch to another将提交范围从一个分支应用到另一个分支
【发布时间】:2021-03-22 06:44:52
【问题描述】:

我有 2 个分支

a -- b -- c -- d -- e -- f -- g -- h     <-- master

a -- b -- c                              <-- Branch1
            

我需要将提交 e、f 和 g 应用到 Branch1

尝试过:

git rebase --onto gSha1 eSha1 hSha1 在 Branch1 上结帐后,它没有工作(如 here 所说)

尝试使用git cherry-pick eSha1^..gSha1,但它也不起作用(如提到的here

【问题讨论】:

  • 您能否快速澄清一下...您的图表表明在某个时候 Branch1 已合并到 master 中。是这样吗?还是您的 Branch1 就在 master 后面? abcd 是否具有相同的提交哈希?在这种情况下,您的图表不应显示从 dd 的合并线。
  • branch1 就在 master 后面。它们确实具有相同的提交哈希。他们没有合并,我误解了图表
  • 申请是什么意思?原来的 e f 和 g 应该怎么办? h呢?

标签: git github gitlab git-commit


【解决方案1】:

如果你愿意 a -- b -- c -- e -- f -- g

来自

                           E---F---G  master
                          /            
                         D
                        /
               A---B---C  Branch1
git rebase --onto branch1 dSha1 gSha1

会给你

                         E'--F'--G'  HEAD
                        /              
                       | D---E---F---G  master
                       |/
               A---B---C  Branch1

接下来将 Branch1 设置为 HEAD:

git branch -f Branch1 HEAD
                         D---E---F---G  master
                        /
               A---B---C---E'--F'--G' Branch1

另类

在没有 D 的提交 C 上将 Branch1 设置为 master 和 rebase Branch1:

git co Branch1
git reset --hard master
git rebase --onto cSha1 dSha1 Branch1

如果你愿意 a -- b -- c -- d -- e -- f -- g (提出的第一个问题)

切换到 Branch1

git checkout Branch1

然后将 Branch1 设置为 g

git reset --hard gSha1

你来了 你可以推送或继续

【讨论】:

  • 这是否应用了从 master 分支到 branch1 的 e、f 和 g 提交?
  • Branch1 将是 a -- b -- c -- d -- e -- f -- g 有应用提交的故事,只需将 Branch1 设置为提交 g。您可以将 Branch1 视为 g 上的指针或标签
  • 对不起,我改变了我的问题
【解决方案2】:

结帐branch1,然后结帐git cherry-pick e f g。不要使用范围;将提交压缩为一个。

【讨论】:

    猜你喜欢
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 2021-04-10
    • 2018-08-12
    • 2016-06-04
    • 2012-09-02
    • 2014-02-20
    • 2016-03-23
    相关资源
    最近更新 更多