【问题标题】:GIT rebase commits to top and bottomGIT rebase 提交到顶部和底部
【发布时间】:2021-04-02 04:15:36
【问题描述】:

我有 3 个分支。 A、B 和 X

    A has a commit - commit A
    B has a commit - commit B
    X has a commit - commit X

我想将 A 和 B 变基为 X

     A branch's commit should be top of X branch's commit
     B branch's commit should be bottom of X branch's commit 

最终的提交日志应该如下所示

    commit A
    commit X
    commit B

请解释一下我可以得到上述最终结果的步骤

【问题讨论】:

  • 你已经尝试了什么?在B 分支上创建一个分支C,使用交互式rebase 重新排序提交,将分支BX 分别重置为CC~1,删除分支C,这样就完成了。
  • 分支是否有共同的祖先?
  • @fluffy 我签出了分支 X,然后运行 ​​'git rebase origin/B' 然后 B 的提交到达 X 提交的底部。有任何像这样的简单命令可以让 A 的提交在 X 的提交之上?
  • @j6t 是的,所有分支都来自同一个主/主分支

标签: git commit rebase


【解决方案1】:

假设main 是共同祖先,我会用git cherry-pick 而不是git rebase 这样做:

git checkout B
git cherry-pick main..X
git branch -f X
git cherry-pick main..A
git branch -f A

无论每个分支仅包含一个提交还是多个提交,这些都有效。如果XA 中只有一个提交,您可以删除main.. 部分。

【讨论】:

    猜你喜欢
    • 2013-01-08
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-04
    • 2018-12-26
    • 2018-07-15
    相关资源
    最近更新 更多