【问题标题】:Git rebasing one branch onto another excluding merges up from parentGit将一个分支重新定位到另一个分支上,不包括从父级合并
【发布时间】:2020-11-20 22:05:22
【问题描述】:

我想将一个特性分支重新定位到另一个永久偏离主分支的特性分支上。有太多的提交要挑选,所以我认为变基是可行的方法,但我不知道如何在 D 之后排除对 master 的更改。

基本上我想:

开始于:

      E-F-G-H [feature_2]
     /
A-B-D-I-K [master]
   \   \ \
    C-G-J-L-M-N [feature_1]

结尾:

              G-M-N [feature_1]
             /
      E-F-G-H [feature_2]
     /
A-B-D-I-K [master]

我尝试了以下方法,但它似乎也应用了提交 J 和 L

git checkout feature_1
git rebase --onto feature_2 B

【问题讨论】:

  • 所以你只是想重写你的feature_1的历史?你可以试试rebase interactive,例如rebase --interactive HEAD~6.
  • 当你往里看时,变基是一种美化的樱桃选择......所以它不像变基可以“自动”摆脱你尝试樱桃采摘时发生的冲突。他们可能会在应用 M 和 N 时出现,对吧?那是因为这些更改适用于来自 J 和 L 合并的更改......所以显然没有办法解决它......除非你在你将执行的 rebase/cherry-pick 中带来一些.

标签: git rebase


【解决方案1】:

您需要确保master 是变基操作的“上游”——这决定了哪些提交将被重写——然后按照您的说明使用--onto 参数。

git checkout feature-1
git rebase --onto feature-2 master

或单命令速记

git rebase --onto feature-2 master feature-1

【讨论】:

    猜你喜欢
    • 2022-11-09
    • 2017-08-04
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-11
    相关资源
    最近更新 更多