git
runtime_error
ai_generated
true
warning: Cannot merge binary files: image.png (HEAD vs. origin/main)
ID: git/conflict-in-binary-file
80%Fix Rate
84%Confidence
1Evidence
2023-04-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| git 2.26.0 | active | — | — | — |
| git 2.33.0 | active | — | — | — |
| git 2.38.0 | active | — | — | — |
Root Cause
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中文
Git 无法自动合并二进制文件(例如图像、PDF),因为它们没有基于文本的差异,导致冲突需要手动解决。
Official Documentation
https://git-scm.com/docs/git-merge#_handling_binary_filesWorkarounds
-
85% success 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
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
-
75% success If both versions are needed, manually copy the correct version from a backup or regenerate the file, then git add image.png
If both versions are needed, manually copy the correct version from a backup or regenerate the file, then git add image.png
-
70% success Use a dedicated binary merge tool like 'git lfs' or 'git-annex' for large binary files to avoid conflicts in the future.
Use a dedicated binary merge tool like 'git lfs' or 'git-annex' for large binary files to avoid conflicts in the future.
中文步骤
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
If both versions are needed, manually copy the correct version from a backup or regenerate the file, then git add image.png
Use a dedicated binary merge tool like 'git lfs' or 'git-annex' for large binary files to avoid conflicts in the future.
Dead Ends
Common approaches that don't work:
-
95% fail
Binary files contain non-text data; editing them as text corrupts the file.
-
80% fail
Most merge tools cannot display a meaningful diff for binaries; the tool may fail or show nothing useful.
-
100% fail
Git still marks the file as conflicted; the merge cannot complete until the conflict is resolved.