Diagnose and Fix Mixed Line Endings
Find and fix files with mixed LF and CRLF line endings that cause git diffs, build failures, and cross-platform compatibility issues.
Detailed Explanation
When LF Meets CRLF
Mixed line endings occur when a single file contains both LF (\n) and CRLF (\r\n) characters. This typically happens when:
- Multiple developers on different OSes edit the same file
- Text is copy-pasted from different sources
- An editor converts some but not all line endings
- Git's
core.autocrlfsetting is misconfigured
Detecting the Mix
The Whitespace Visualizer's Line Endings panel reports the exact composition:
Mixed: LF (47), CRLF (3)
This tells you that 47 lines use LF and 3 use CRLF. You can scroll through the visualization to find exactly which lines have the wrong ending — look for the green ←↵ markers among the ↵ markers (or vice versa).
Impact on Git
Git tracks line ending changes as modifications. If your file has mixed endings and you normalize them, Git will show every affected line as changed. This is why it's important to:
- Normalize early, in a dedicated commit
- Configure
.gitattributeswith* text=autoor specific rules - Use
git add --renormalize .after changing settings
Impact on Tooling
| Tool | Symptom |
|---|---|
| diff / patch | Patches may fail to apply cleanly |
| linters | ESLint, Prettier may flag or auto-fix endings |
| compilers | Some compilers or preprocessors choke on mixed endings |
| Docker | CRLF in COPY'd scripts causes runtime failures |
Fixing Mixed Endings
- Paste the file content into the Whitespace Visualizer.
- Confirm mixed endings in the Line Endings panel.
- In Clean, select CRLF (if normalizing to LF) or LF (if normalizing to CRLF).
- Click Clean and copy the result.
For large projects, configure .gitattributes and run git add --renormalize . to fix all files at once.
Use Case
A team notices their git diffs show entire files as changed even though only one line was edited. The Whitespace Visualizer reveals mixed line endings throughout the file. They normalize to LF, add a .gitattributes rule, and subsequent diffs show only actual code changes.