Git Reference ยท Files and Formats
The text, eol and crlf attributes
Reference for the text, eol and crlf attributes in .gitattributes: normalize line endings in the repository and choose LF or CRLF on checkout.
The text and eol attributes in .gitattributes decide how Git treats line endings. text says "this file is text, so convert its line endings when it enters or leaves the repository". eol says which ending the working-tree copy should use after checkout. Together they let a repository store one canonical form (LF) while each file shows the right ending on disk.
The older crlf attribute is a legacy spelling of the same idea. Prefer text and eol in new files; they are clearer, and they override personal settings such as core.autocrlf.
*.txt text
*.sh text eol=lf
*.bat text eol=crlf
*.png -text
* text=auto
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
<pattern> text # always normalize <pattern> -text # never convert <pattern> text=auto # normalize only if Git guesses it is text <pattern> eol=lf | eol=crlf <pattern> crlf | -crlf | crlf=input # legacy
| Setting | Meaning |
|---|---|
text |
The file is text. On add, CRLF becomes LF in the repository. On checkout, the ending follows eol, or core.eol / core.autocrlf when eol is unset. |
-text |
The file is not text: no conversion at all. |
text=auto |
Git inspects the content. Files that look like text are normalized, files that look binary are left alone. |
| unspecified | Fall back to core.autocrlf and its automatic detection. |
eol=lf |
Working-tree copy uses LF. Implies text when text is not set otherwise. |
eol=crlf |
Working-tree copy uses CRLF on every platform. |
crlf / -crlf / crlf=input |
Old names for text, -text and eol=lf. |
Edge cases: a file with a lone CR or other odd content can make text=auto classify it as binary. With core.safecrlf set to true, Git refuses a conversion it could not reverse exactly.
Usage notes
- Check the result with
git ls-files --eol. It printsi/(index),w/(working tree) andattr/columns, such asi/lf w/crlf attr/text=auto. A mismatch betweeni/and what you want is the signal to renormalize. - Existing files are not rewritten automatically. After adding or changing the attributes, run
git add --renormalize .and commit once. Otherwise old commits keep CRLF. eolbeatscore.autocrlf. A committed.gitattributesmakes the behavior identical for everyone, which a per-user setting cannot.- Mark real binaries
-text(orbinary). Normalizing an image or archive corrupts it. - Shell scripts need
eol=lf. A\rin a shebang line gives "bad interpreter" errors on Linux and macOS. - Windows batch files are safest with
eol=crlf, because labels andgotocan misbehave with bare LF. - The normalization commit dominates
git blame. List it in .git-blame-ignore-revs. working-tree-encodingis a separate attribute for re-encoding (for example UTF-16) on checkout; it combines withtext.