🔀 Fix Autocrlf Rewriting a Binary File on Checkout
Git’s core.autocrlf setting decides whether to convert line endings on checkout and commit, but that decision is only supposed to apply to files Git itself classifies as text — a binary file that Git’s heuristic misdetects as text (common for certain font files, small images, or custom data formats with a lot of ASCII-range bytes near the start) gets its line endings silently rewritten on checkout, corrupting it in a way that’s invisible until something tries to actually open the file.
🔎 The Problem
$ git diff --stat assets/icon.ico | Bin 4286 -> 4288 bytes # A binary file changed size after a plain checkout, with # no intentional edit - autocrlf converted bytes it mistook for CRLF
✅ Fix: Tell Git Explicitly Which Files Are Binary
- Add an entry to
.gitattributesmarking the affected path or extension as binary explicitly, e.g.*.ico binary, which overrides Git’s own text/binary heuristic entirely for that pattern. - Re-normalize the repository after adding the attribute (
git add --renormalize .) so the already-corrupted blob in history gets replaced with a clean, byte-for-byte accurate version going forward. - For a whole class of custom or uncommon binary formats, add a broader
.gitattributesrule up front on new repositories rather than waiting to discover each misdetected extension one corruption at a time.
🚨 Why This Is Dangerous
- Because the corruption only shows up as a file that ‘changed’ with no diff content to review, it’s easy for a reviewer to approve the commit without realizing the binary itself is now broken.
Autocrlf isn’t guessing at your intent — it’s trusting Git’s own text/binary detection, and that detection can be wrong.





