【问题标题】:Why is Git Rebase Refusing to squash a merge为什么 Git Rebase 拒绝压缩合并
【发布时间】:2020-10-29 22:21:05
【问题描述】:

我正在尝试将前 14 个提交压缩在一起:git rebase -p -i HEAD~14。下图显示了我要压缩的提交。提交f101fff106d6a1cb904b7389001a588c3656d21e1bfa 是我对develop 所做的合并。

问题是,在我存在 rebase 后,我收到以下错误:

拒绝压缩合并:656d21e1bfa84b866031e904c303662878370d14

我不明白为什么会出现这个错误。我该如何解决?


    pick 290c32355fd Squash all commits
    s 4aa246bc4c5 Squash Commits
    s 656d21e1bfa merge with develop
    s a7448275954 tasks to do
    s 4c6198cd0f0 fix print
    pick f101fff106d Merge remote-tracking branch 'origin' into into TEST_ENGINE
    s 30f9adbe65a remove unused check
    s 7343e3565ad fix error
    s 1e3dc014f67 fix isokToupdate
    s c16412a7f83 fix isokToupdate
    pick 6a1cb904b73 Merge remote-tracking branch 'origin' into TEST_ENGINE
    pick 89001a588c3 Merge remote-tracking branch 'origin' into TEST_ENGINE
    s a32ce67d389 fix namespace
    s 2d0c8ee55e8 Refactor code and correct functional errors
    
    # Rebase a2c59ed4e21..2d0c8ee55e8 onto a2c59ed4e21 (14 commands)
    #
    # Commands:
    # p, pick = use commit
    # r, reword = use commit, but edit the commit message
    # e, edit = use commit, but stop for amending
    # s, squash = use commit, but meld into previous commit
    # f, fixup = like "squash", but discard this commit's log message
    # x, exec = run command (the rest of the line) using shell
    # d, drop = remove commit
    #
    # These lines can be re-ordered; they are executed from top to bottom.
    #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    #
    # However, if you remove everything, the rebase will be aborted.
    #
    # Note that empty commits are commented out

【问题讨论】:

    标签: git rebase squash


    【解决方案1】:

    首先:尽量不要将git rebase -p 与大多数交互式操作(包括挤压、修复或重新排列)结合使用,因为它可能会导致一系列不良行为。如果您的 Git 版本是 2.18 或更高版本,请使用新的--rebase-merges 选项(简称git rebase -r),它的行为要好得多。

    至于您看到的特定错误:在技术上根本不可能重新合并,git rebase -p 和新改进的git rebase -r 都没有这样做。他们所做的是重新执行合并。当他们重新执行合并时,这正是他们所做的:通过运行 git merge 重新执行合并。

    git rebase 所做的 squash 和修复操作或多或少等同于使用 git commit --amend(在旧的交互式 shell 脚本中,实际上 运行 git commit --amend)。但是git merge 没有--amend 的等价物:Git 只是不知道该怎么做。

    当使用新的-r 选项时,您应该能够删除一个合并,如果您只想省略它;或者,如果你想把它变成一个 squash-not-really-a-merge,你可以用适当的 exec git merge --squash 命令替换 merge 命令。仍然需要第二次交互式 -r rebase 才能将生成的提交压缩为更早的提交。

    【讨论】:

      猜你喜欢
      • 2017-12-25
      • 1970-01-01
      • 2011-03-09
      • 2020-02-21
      • 2012-10-22
      • 2014-06-30
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      相关资源
      最近更新 更多