【问题标题】:Git rebase and automatically update branch pointer?Git rebase并自动更新分支指针?
【发布时间】:2020-08-23 14:09:51
【问题描述】:

我有一组如下分支:

            * 444ddd - somefeature3
           /
          * 333ccc - somefeature2
         /
        * 222bbb - somefeature1
       /
------* 111aaa - master

如果我在一个分支上(假设somefeature3 没有somefeature2somefeature1 存在),我可以通过执行git rebase -i 111aaa 来更新我的所有提交。换句话说,我可以从这个出发:

            * 444ddd - somefeature3
           /
          * 333ccc
         /
        * 222bbb
       /
------* 111aaa - master

...到这个:

            * 444eee - somefeature3
           /
          * 333ddd
         /
        * 222ccc
       /
------* 111aaa - master

特别是,提交222bbb 被替换为222ccc333ccc 被替换为333ddd444ddd 被替换为444eee

但是,如果我关心分支指针 somefeature2somefeature1,它们将不会在这种情况下得到更新。我会从这里开始:

            * 444ddd - somefeature3
           /
          * 333ccc - somefeature2
         /
        * 222bbb - somefeature1
       /
------* 111aaa - master

...到这个:

            * 444eee - somefeature3
           /
          * 333ddd        * 333ccc - somefeature2
         /               /
        * 222ccc        * 222bbb - somefeature1
       /               /
------* --------------*
       111aaa - master

我希望最终状态看起来像这样,分支指针somefeature2somefeature1somefeature3 一起更新:

            * 444eee - somefeature3
           /
          * 333ddd - somefeature2
         /
        * 222ccc - somefeature1
       /
------* 111aaa - master

有什么方法可以让 Git 自动更新 somefeature1somefeature2 的分支指针以及 git rebase -i 的一部分,从而产生这个结束状态?

(meta:这类似于this question,但它进一步询问是否可以让 Git 自动执行适当的 foo)

【问题讨论】:

  • 请在你的 rebase 操作后向我们展示你想要的分支结构。
  • 编辑了我的问题以包含更多图表和细节。
  • Git 确实需要一个“多分支”变基命令,针对这些情况。现在git rebase -r 存在,内部rebase 代码有足够的机制来实现正确的结果;它只需要一些 external 方法来指定要更新的正确名称集。

标签: git branch rebase feature-branch


【解决方案1】:

我最容易做到的是使用交互式变基并在选择这些提示之后添加exec git branch -f branchname。如果这对您来说很常见,那么您就处于脚本领域,请使用您最喜欢的编辑器在每一行上运行git for-each-ref --points-at,并使用一种可以输出更新的格式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-28
    • 2021-08-18
    • 2023-02-11
    • 2021-05-09
    • 2020-04-04
    • 2017-12-22
    • 2016-02-06
    • 2021-08-20
    相关资源
    最近更新 更多