You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git Rebase拒绝压缩合并提交的原因及解决方法

Why You're Seeing This Error

Git refuses to squash merge commits because they have two parent commits (tracking the branches you merged). Squashing a merge would discard that branch history, and the -p (--preserve-merges) flag you used is explicitly meant to keep your merge structure intact—so trying to squash a merge directly conflicts with that goal.

How to Fix It

You have a few options depending on whether you want to keep the merge history or flatten all commits:

Option 1: Keep Merge Commits & Adjust Squashing

If preserving the merge with develop is important, modify your interactive rebase todo list to keep the merge commit as a pick instead of trying to squash it. You can still squash the regular commits around it:

  1. If your rebase is already stuck, abort it first:
    git rebase --abort
    
  2. Restart the interactive rebase with -p:
    git rebase -p -i HEAD~14
    
  3. In the todo list, change the line for merge commit 656d21e1bfa from s to p. Your adjusted list will look like this:
    pick 290c32355fd Squash all commits
    s 4aa246bc4c5 Squash Commits
    pick 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
    
  4. Save and exit the editor—Git will now process the rebase without blocking, preserving your merge commits while squashing the regular commits into the nearest preceding pick.

Option 2: Flatten All Commits (Discard Merge History)

If you don’t need to track the merge branches and just want to combine all 14 commits into a single one, drop the -p flag entirely:

  1. Abort the current rebase:
    git rebase --abort
    
  2. Run the rebase without preserving merges:
    git rebase -i HEAD~14
    
  3. Set the first commit to pick and change all other lines (including merge commits) to s (squash). This tells Git to replay every commit as a patch and combine them all into one. Note: You might hit more conflicts here since Git is flattening the merge structure, but once resolved, you’ll end up with a single commit containing all changes.

Option 3: Adjust Individual Merge Commits

If you just need to tweak a merge commit’s message (not squash it), replace s with r (reword) in the todo list. If you need to modify the merge’s content, use e (edit)—but this is more advanced and requires manually resolving the merge again.

内容的提问来源于stack exchange,提问作者gringo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 13:38:12