错误:无法应用 <哈希>... <提交信息>(变基冲突)
error: could not apply <hash>... <commit-message> (rebase conflict)
ID: git/divergent-branch-rebase-conflict
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| git 2.39.0 | active | — | — | — |
| git 2.40.1 | active | — | — | — |
| git 2.41.0 | active | — | — | — |
根因分析
变基操作遇到了无法自动解决的合并冲突,因为当前分支和目标分支已经分叉,补丁无法干净地应用。
English
A rebase operation encountered a merge conflict that cannot be automatically resolved because the current branch and the target branch have diverged, and the patch does not cleanly apply.
官方文档
https://git-scm.com/docs/git-rebase#_conflict_resolution解决方案
-
Manually edit the conflicted file to resolve conflict markers (<<<<<<<, =======, >>>>>>>), then run 'git add <file>' and 'git rebase --continue'
-
Use a mergetool like 'git mergetool' to visually resolve conflicts with KDiff3 or vimdiff, then continue the rebase
-
If the conflict is too complex, abort with 'git rebase --abort' and use 'git merge' instead, which may handle divergent histories more gracefully
无效尝试
常见但无效的做法:
-
65% 失败
Skipping the commit removes its changes permanently from the rebased branch, leading to data loss or incomplete integration.
-
80% 失败
Git will still detect unresolved conflicts because the conflict markers remain in the file, causing the rebase to abort or produce corrupted content.
-
50% 失败
This discards all uncommitted changes and the rebase state, but does not resolve the underlying divergence; the same conflict will reappear on next rebase attempt.