解决 Git 合并分支遇到二进制文件冲突 (Binary files conflict)
分析 Git 遇到图片、压缩包等二进制文件冲突诱因,详解 checkout --ours 与 --theirs 单向采纳规范。
问题现象
在合并分支(git merge)时提示冲突:
CONFLICT (content): Merge conflict in assets/logo.png
Automatic merge failed; fix conflicts and then commit the result.
由于是图片或打包二进制文件,无法像普通文本文件那样打开插入 <<<<<<< 标记手动编辑合并。
触发根因
二进制文件不具备行概念,Git 无法通过三方合并算法进行逐行自动补丁融合,必须二选一。
解决方案
方案一:采纳当前分支版本(--ours)
如果决定保留本地当前分支的图片:
git checkout --ours assets/logo.png
git add assets/logo.png
方案二:采纳被合并分支版本(--theirs)
如果决定采纳来自远端或特性分支的新图片:
git checkout --theirs assets/logo.png
git add assets/logo.png
解决完成后提交:
git commit -m "chore: resolve binary conflict in logo.png"
验证方法
执行 git status,工作区完全干净,合并圆满完成。


