Skip to content
Tutorials Center
My learning

Topics

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.

Terminal
*.txt   text
*.sh    text eol=lf
*.bat   text eol=crlf
*.png   -text
*       text=auto

Try it

Bash Inspect what the attributes do

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.

Bash LF in the repository, CRLF on disk

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

Terminal
<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 prints i/ (index), w/ (working tree) and attr/ columns, such as i/lf w/crlf attr/text=auto. A mismatch between i/ 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.
  • eol beats core.autocrlf. A committed .gitattributes makes the behavior identical for everyone, which a per-user setting cannot.
  • Mark real binaries -text (or binary). Normalizing an image or archive corrupts it.
  • Shell scripts need eol=lf. A \r in a shebang line gives "bad interpreter" errors on Linux and macOS.
  • Windows batch files are safest with eol=crlf, because labels and goto can misbehave with bare LF.
  • The normalization commit dominates git blame. List it in .git-blame-ignore-revs.
  • working-tree-encoding is a separate attribute for re-encoding (for example UTF-16) on checkout; it combines with text.