git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git EOL Normalization

From
Dmitry Potapov <dpotapov@gmail.com>
Date
May 25, 2011, 17:58 UTC
Message-ID
<BANLkTik3iRKx4P_3nbzygadmLPEOr2vGhA@mail.gmail.com>
In-Reply-To
<29536877.39971.1306336806278.JavaMail.root@mail.hq.genarts.com>
On Wed, May 25, 2011 at 7:20 PM, Stephen Bash <bash@genarts.com> wrote:
Show 5 quoted lines
>
> The open questions for me are:
>  1) what is the actual text file detection algorithm?
>  2) what is the autocrlf LF/CRLF detection algorithm?
>  3) how does autocrlf handle mixed line endings? (either in the working copy or repo)

Git looks at the text attribute of a file. If it is set or unset then it treats the file as text or binary accordingly. If the text attribute is 'auto', or it is unspecified but core.autocrlf is true, then git uses heuristics to detect text files.

Currently, the following heuristics are used:

A file is considered as text if it does not have '\0' or a bare CR, and the number of non-printable characters is less than 1 in 128.

Non-printable characters are DEL (127) and anything less than 32 except CR, LF, BS, HT, ESC and FF.

Also, to avoid problems with autocrlf=true when someone has already put a text file with CRLF, CRLF->LF conversion happens only if the tracked file in the index does not have any CR.

Dmitry PS I wrote this mostly from my memory, so I could miss some detail.

Previous: Stephen BashNext: Stephen Bash
Message 2 of 8 in “Git EOL Normalization”
  1. Stephen BashMay 25, 2011
  2. Dmitry PotapovMay 25, 2011
  3. Stephen BashMay 25, 2011
  4. Jakub NarebskiMay 26, 2011
  5. Dmitry PotapovMay 26, 2011
  6. Junio C HamanoMay 26, 2011
  7. Stephen BashMay 26, 2011
  8. Drew NorthupMay 31, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.