Line ending (LF and CRLF)
Definition
LF and CRLF are different character sequences that mark the end of a line in text files.
A line ending marks the transition to the next line in a text file. LF uses the control character Line Feed; CRLF combines Carriage Return and Line Feed. This differs from a merely visible line break inserted by an editor due to window width.
Simply explained
A file contains invisible characters for new lines. Different systems may expect different variants for this, although the text initially looks the same.
Why it matters in practice
Uniform line endings facilitate collaboration across operating systems and prevent unnecessary changes in version comparisons.
Example from business
Possible example: A team sets LF for its shell scripts so that editing under Windows does not introduce unexpected line ending changes into the repository.
Limits and pitfalls
- Automatic conversions can make entire files appear changed. Binary files must not be normalized like text; settings should match the respective file type.
Origin & history
The terms originate from control characters for carriage return and line feed. Different system conventions still shape the storage of text files today.
Use in mid-sized companies
- Development teams can specify line endings per file type in .gitattributes and treat normalization changes separately from content adjustments.
Frequently asked questions
Are line endings a character encoding?
No. UTF-8 describes the encoding of characters; LF or CRLF defines which character sequence marks a line break.
Sources
- o. J., gitattributes – End-of-line conversion · Git-Projekt, o. J., gitattributes – End-of-line conversion
Editorially reviewed on: