CRLF vs LF: understanding text-file line endings
A line ending is a character sequence that marks where one text line ends and the next begins. Windows files commonly use CRLF; Unix-like systems commonly use LF. The difference is easy to miss in an editor but can affect diffs, scripts, and exact text processing.
Two common conventions
Unix-like systems traditionally use LF (line feed). Windows text commonly uses CRLF (carriage return plus line feed). Git, editors, runtimes, and file formats can normalize or preserve these characters depending on configuration.
What TinyDevTools does
The current line-oriented tools split input with a CRLF-or-LF pattern, so either common convention is accepted. Their outputs are joined with LF.
How the bytes differ
LF is U+000A (line feed, commonly written \n). CRLF is U+000D followed by U+000A (carriage return plus line feed, commonly written \r\n). Older classic Mac text used CR alone; the TinyDevTools line tools do not treat lone CR as a separator.
A file can also contain mixed endings. Some editors hide that difference or normalize it while saving, so check the file or repository settings before changing line endings across an entire project.
Why diffs can look larger than the change
If one tool rewrites every line ending, version control may show every line as changed even though the visible words are the same. This obscures the meaningful edit and can create noisy merges. A file-specific rule in .gitattributes is often preferable to relying on each contributor's machine-wide setting.
# Example for text files in a repository: *.txt text eol=lf
This is a repository policy example, not a universal setting: choose the convention required by the project and check how existing files are tracked before applying it.
Check before normalizing
- Inspect the file's line-ending indicator in your editor or compare its bytes with a suitable local tool.
- Check whether the file is expected to use LF, CRLF, or a specific convention required by a consumer.
- Make a focused conversion, then review the diff and test scripts or parsers that read the file.
TinyDevTools accepts LF and CRLF for its line-oriented transformations, but it emits LF. It is meant for quick text cleanup, not as a line-ending-preserving file converter.
Why it matters
Line-ending changes can create noisy diffs, affect shell scripts, and make exact string comparisons surprising. If Git shows every line modified when content appears unchanged, line endings are one of the first things to inspect.
Advertisements