Must read post when using Git on line endings: What’s the best CRLF handling strategy with git? – Stack Overflow
Posted by jpluimers on 2020/09/23
Start with this must read post: cross platform – What’s the best CRLF handling strategy with git? – Stack Overflow.
Then read all the links in that answer, especially
- Git – gitattributes Documentation.
- Dealing with line endings · GitHub Help.
- Mind the End of Your Line ∙ Timothy Clem ∙ Adaptive Patchwork.
Then see if you agree with my conclusion:
use a .gitattributes file to steer line ending conversions on a per-repository base.
I usually try to have git not mess with any line endings: check-out as-is, check-in as is.
Historically this has been a mess (not limited to, but prevalent on Windows installations), not just because core.autocrlf has been superseded by core.eol, so below are some links that will help.
TL;DR
Always execute these after installing git:
git config --global core.autocrlf false
git config --global core.eol native
If needed, repeat in the current repository:
git config --local core.autocrlf false
git config --local core.eol native
Finally verify the settings with git config --list --show-origin (via [WayBack] Where does git config –global get written to? – Stack Overflow)
Note
The
git config listwill show equals signs. Do NOT use these when setting values: that will silently fail.So these fail:
git config --global core.autocrlf=false
git config --global core.eol=native
git config --local core.autocrlf=false
git config --local core.eolnativeDespite the output when listing on a machine that already had these values et:
git config --list | grep -w 'core.autocrlf\|core.eol'
core.autocrlf=false
core.eol=native
core.autocrlf=false
core.eol=native
References
- [WayBack] Dealing with line endings – User Documentation
- [WayBack] Git – gitattributes Documentation: text:
core.autocrlfoverridescore.eol- Unsetting the
textattribute on a path tells Git not to attempt any end-of-line conversion upon checkin or checkout. - If
core.safecrlfis set to “true” or “warn”, git verifies if the conversion is reversible for the current setting ofcore.autocrlf. For “true”, git rejects irreversible conversions; for “warn”, git only prints a warning but accepts an irreversible conversion.
- [WayBack] Git – gitattributes Documentation: end of line conversion
- [WayBack] Source: Git – git-config Documentation: core.eol
- [WayBack] Source: Git – git-config Documentation: core.autocrlf
- [WayBack] Source: Git – git-config Documentation: core.safecrlf
- [WayBack] line endings – Why should I use core.autocrlf=true in Git? – Stack Overflow
- [WayBack] newline – How line ending conversions work with git core.autocrlf between different operating systems – Stack Overflow
-
| Resulting conversion when | Resulting conversion when | committing files with various | checking out FROM repo - | EOLs INTO repo and | with mixed files in it and | core.autocrlf value: | core.autocrlf value: -------------------------------------------------------------------------------- File | true | input | false | true | input | false -------------------------------------------------------------------------------- Windows-CRLF | CRLF -> LF | CRLF -> LF | as-is | as-is | as-is | as-is Unix -LF | as-is | as-is | as-is | LF -> CRLF | as-is | as-is Mac -CR | as-is | as-is | as-is | as-is | as-is | as-is Mixed-CRLF+LF | as-is | as-is | as-is | as-is | as-is | as-is Mixed-CRLF+LF+CR | as-is | as-is | as-is | as-is | as-is | as-is - I explored 3 possible values for commit and checkout cases and this is the resulting table:
╔═══════════════╦══════════════╦══════════════╦══════════════╗ ║ core.autocrlf ║ false ║ input ║ true ║ ╠═══════════════╬══════════════╬══════════════╬══════════════╣ ║ git commit ║ LF => LF ║ LF => LF ║ LF => CRLF ║ ║ ║ CR => CR ║ CR => CR ║ CR => CR ║ ║ ║ CRLF => CRLF ║ CRLF => LF ║ CRLF => CRLF ║ ╠═══════════════╬══════════════╬══════════════╬══════════════╣ ║ git checkout ║ LF => LF ║ LF => LF ║ LF => CRLF ║ ║ ║ CR => CR ║ CR => CR ║ CR => CR ║ ║ ║ CRLF => CRLF ║ CRLF => CRLF ║ CRLF => CRLF ║ ╚═══════════════╩══════════════╩══════════════╩══════════════╝
-
- [WayBack] windows – Why does git keep messing with my line endings? – Stack Overflow
- [WayBack] Mind the End of Your Line ∙ Adaptive Patchwork
- [WayBack] Configuring how line-endings are handled by git – SCAPE – Confluence
–jeroen
PS: To look at the various local and global settings, read Where does git config –global get written to? – Stack Overflow.






Leave a comment