git runtime_error ai_generated true

警告:无法合并二进制文件:image.png(HEAD vs. origin/main)

warning: Cannot merge binary files: image.png (HEAD vs. origin/main)

ID: git/conflict-in-binary-file

其他格式: JSON · Markdown 中文 · English
80%修复率
84%置信度
1证据数
2023-04-05首次发现

版本兼容性

版本状态引入弃用备注
git 2.26.0 active
git 2.33.0 active
git 2.38.0 active

根因分析

Git 无法自动合并二进制文件(例如图像、PDF),因为它们没有基于文本的差异,导致冲突需要手动解决。

English

Git cannot automatically merge binary files (e.g., images, PDFs) because they have no text-based diff, leading to a conflict that requires manual resolution.

generic

官方文档

https://git-scm.com/docs/git-merge#_handling_binary_files

解决方案

  1. Choose one version explicitly: git checkout --ours image.png (keep HEAD version) or git checkout --theirs image.png (keep incoming version), then git add image.png
  2. If both versions are needed, manually copy the correct version from a backup or regenerate the file, then git add image.png
  3. Use a dedicated binary merge tool like 'git lfs' or 'git-annex' for large binary files to avoid conflicts in the future.

无效尝试

常见但无效的做法:

  1. 95% 失败

    Binary files contain non-text data; editing them as text corrupts the file.

  2. 80% 失败

    Most merge tools cannot display a meaningful diff for binaries; the tool may fail or show nothing useful.

  3. 100% 失败

    Git still marks the file as conflicted; the merge cannot complete until the conflict is resolved.