# Why doesn't git core.eol=lf work?

7 messages from 2025-07-12 to 2025-07-13. Participants: Jason Cho, Torsten Bögershausen, Johannes Sixt, Lidong Yan.
Thread: https://gitlist.dev/t/63782

## Jason Cho, 2025-07-12 09:45

Subject: Why doesn't git core.eol=lf work?
Message-ID: <QcbAE4JJXpU-NcQ1loYdHthi-nYA2ZXcuuetCHE_0N0fRi0mdaf90VaLk0Y2ehrnVzoZraYO7jLhB7Pl68_k4l3HCqkFVGuMOzZ26cHYkfc=@proton.me>
URL: https://gitlist.dev/e/QcbAE4JJXpU-NcQ1loYdHthi-nYA2ZXcuuetCHE_0N0fRi0mdaf90VaLk0Y2ehrnVzoZraYO7jLhB7Pl68_k4l3HCqkFVGuMOzZ26cHYkfc%3D%40proton.me
In-Reply-To: <8jPyf4EU-z7W6OHX4j_kba2G-1c2RIDtgBcSkFjWSNhMuE6pxOOyxSGBnguoZvuDQSaJPypH0u1vLJf6FBX_ahUn3bBO_1DVscfOQm4Jovw=@proton.me>

```
ˋˋˋMINGW64 /tmp/summer-temp/dbeaver/docs ((e4219ccb38...))
$ git log -1 --patch license_header.txt
commit b5121d4a6e8f3f21079920180b0fb14ada6d3349
Author: serge-rider <serge@jkiss.org>
Date:   Thu Jan 10 21:56:55 2019 +0300

    License header update (2019)

diff --git a/docs/license_header.txt b/docs/license_header.txt
index 86de505a18..d75b48e98e 100644
--- a/docs/license_header.txt
+++ b/docs/license_header.txt
@@ -1,5 +1,5 @@
    DBeaver - Universal Database Manager
-   Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
+   Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)^M

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.

MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
$ git check-attr --all -- license_header.txt

MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
$ rm license_header.txt

MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
$ git -c core.autocrlf=false -c core.eol=lf checkout -f HEAD -- license_header.txt

MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
$ cat -A license_header.txt
   DBeaver - Universal Database Manager^M$
   Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)^M$
^M$
   Licensed under the Apache License, Version 2.0 (the "License");^M$
   you may not use this file except in compliance with the License.^M$
   You may obtain a copy of the License at^M$

MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
$ git --version
git version 2.47.0.windows.2
ˋˋˋ

I ask git to force checkout license_header.txt with LF line ending, but `cat` tells me the file is checked out with CRLF. Why?


```

## Torsten Bögershausen, 2025-07-12 10:30

Subject: Re: Why doesn't git core.eol=lf work?
Message-ID: <20250712103030.GA30568@tb-raspi4>
URL: https://gitlist.dev/e/20250712103030.GA30568%40tb-raspi4
In-Reply-To: <QcbAE4JJXpU-NcQ1loYdHthi-nYA2ZXcuuetCHE_0N0fRi0mdaf90VaLk0Y2ehrnVzoZraYO7jLhB7Pl68_k4l3HCqkFVGuMOzZ26cHYkfc=@proton.me>

```
On Sat, Jul 12, 2025 at 09:45:39AM +0000, Jason Cho wrote:
> ˋˋˋMINGW64 /tmp/summer-temp/dbeaver/docs ((e4219ccb38...))
> $ git log -1 --patch license_header.txt
> commit b5121d4a6e8f3f21079920180b0fb14ada6d3349
> Author: serge-rider <serge@jkiss.org>
> Date:   Thu Jan 10 21:56:55 2019 +0300
> 
>     License header update (2019)
> 
> diff --git a/docs/license_header.txt b/docs/license_header.txt
> index 86de505a18..d75b48e98e 100644
> --- a/docs/license_header.txt
> +++ b/docs/license_header.txt
> @@ -1,5 +1,5 @@
>     DBeaver - Universal Database Manager
> -   Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
> +   Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)^M
> 
>     Licensed under the Apache License, Version 2.0 (the "License");
>     you may not use this file except in compliance with the License.
> 
> MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
> $ git check-attr --all -- license_header.txt
> 
> MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
> $ rm license_header.txt
> 
> MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
> $ git -c core.autocrlf=false -c core.eol=lf checkout -f HEAD -- license_header.txt
> 
> MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
> $ cat -A license_header.txt
>    DBeaver - Universal Database Manager^M$
>    Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)^M$
> ^M$
>    Licensed under the Apache License, Version 2.0 (the "License");^M$
>    you may not use this file except in compliance with the License.^M$
>    You may obtain a copy of the License at^M$
> 
> MINGW64 /tmp/summer-temp/dbeaver/docs ((a3f59b66ed...))
> $ git --version
> git version 2.47.0.windows.2
> ˋˋˋ
> 
> I ask git to force checkout license_header.txt with LF line ending, but `cat` tells me the file is checked out with CRLF. Why?
> 
Side note: Did you  ?
I would suspect that core.autocrlf=false switches off the CRLF handling.
And this could be a command line:
git -c core.autocrlf=input -c core.eol=lf checkout -f HEAD -- license_header.txt

But now to the real stuff:
It may be that your file had been commited with LF or mixed CRLF into the repo.
In this case will Git not change CRLF into LF at checkout.
What does
git ls-files --eol license_header.txt
give you ?

Beside that, I would recommend to set up a .gitatrributes file
and add it to the repo.
echo "* text=auto" >.gitattributes
git add --renormalize .
git commit -m "Normalize line endings"


```

## Jason Cho, 2025-07-12 10:56

Subject: Re: Why doesn't git core.eol=lf work?
Message-ID: <hmmjz8ewCl8dl_K4NrydJHLRzLtjs8vGanKXkbJjDPgaaZvj9HzyzEkrY9WlciWgx0iNlcWPhwGpl1E2gxQkRpG_10KgmHDareAH7LQj33A=@proton.me>
URL: https://gitlist.dev/e/hmmjz8ewCl8dl_K4NrydJHLRzLtjs8vGanKXkbJjDPgaaZvj9HzyzEkrY9WlciWgx0iNlcWPhwGpl1E2gxQkRpG_10KgmHDareAH7LQj33A%3D%40proton.me
In-Reply-To: <20250712103030.GA30568@tb-raspi4>

```
> But now to the real stuff:
> It may be that your file had been commited with LF or mixed CRLF into the repo.
> In this case will Git not change CRLF into LF at checkout.
> What does
> git ls-files --eol license_header.txt
> give you ?


$ git ls-files --eol license_header.txt
i/crlf  w/crlf  attr/                   license_header.txt


 
> Beside that, I would recommend to set up a .gitatrributes file
> and add it to the repo.
> echo "* text=auto" >.gitattributes
> 
> git add --renormalize .
> git commit -m "Normalize line endings"

I am building a tool to analyze codebases, such as which function is moved from one file to another. Different line endings fail string equality.

Admittedly I can make a local commit to normalize all files. But it's best if a simple config `core.eol` can work.

```

## Johannes Sixt, 2025-07-12 13:35

Subject: Re: Why doesn't git core.eol=lf work?
Message-ID: <23f2bbea-1294-4773-89d8-b270e2c3bb52@kdbg.org>
URL: https://gitlist.dev/e/23f2bbea-1294-4773-89d8-b270e2c3bb52%40kdbg.org
In-Reply-To: <QcbAE4JJXpU-NcQ1loYdHthi-nYA2ZXcuuetCHE_0N0fRi0mdaf90VaLk0Y2ehrnVzoZraYO7jLhB7Pl68_k4l3HCqkFVGuMOzZ26cHYkfc=@proton.me>

```
Am 12.07.25 um 11:45 schrieb Jason Cho:
> ˋˋˋMINGW64 /tmp/summer-temp/dbeaver/docs ((e4219ccb38...))
> $ git log -1 --patch license_header.txt
> commit b5121d4a6e8f3f21079920180b0fb14ada6d3349
> Author: serge-rider <serge@jkiss.org>
> Date:   Thu Jan 10 21:56:55 2019 +0300
> 
>     License header update (2019)
> 
> diff --git a/docs/license_header.txt b/docs/license_header.txt
> index 86de505a18..d75b48e98e 100644
> --- a/docs/license_header.txt
> +++ b/docs/license_header.txt
> @@ -1,5 +1,5 @@
>     DBeaver - Universal Database Manager
> -   Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
> +   Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)^M
> 
>     Licensed under the Apache License, Version 2.0 (the "License");
>     you may not use this file except in compliance with the License.
> 

Since you posted `git diff` output, may I ask if your concern is
actually the ^M in the diff output, which you intend to fix with
automatic CRLF-to-LF conversion?

In that case, the simpler solution is to set core.whitespace such that
it includes 'cr-at-eol' to convince `git diff` not to mark the CR in the
CRLF pair as a trailing whitespace error.

-- Hannes


```

## Jason Cho, 2025-07-12 19:15

Subject: Re: Why doesn't git core.eol=lf work?
Message-ID: <sAxC2ASixUyCVtsk22zrxI2vAeM546T7O2tyWIS2vv_TGFo2OXWegg8J_r0zGzo5bZOA-BrwHa5yjAv2-Ewusjv9Fa9YYocrRkaIfpxhv_c=@proton.me>
URL: https://gitlist.dev/e/sAxC2ASixUyCVtsk22zrxI2vAeM546T7O2tyWIS2vv_TGFo2OXWegg8J_r0zGzo5bZOA-BrwHa5yjAv2-Ewusjv9Fa9YYocrRkaIfpxhv_c%3D%40proton.me
In-Reply-To: <23f2bbea-1294-4773-89d8-b270e2c3bb52@kdbg.org>

```
> 
> Since you posted `git diff` output, may I ask if your concern is
> actually the ^M in the diff output, which you intend to fix with
> automatic CRLF-to-LF conversion?
> 

No, my intent is to find moved or duplicated text among files. 

Let's say license_header.txt has 

DBeaver - Universal Database Manager^M
Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)

and another.txt has

DBeaver - Universal Database Manager
Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)

My tool doesn't think the two pieces of txt the same because of ^M.

Although my tool can do normalization internally, if git checks out files to CRLF due to core.autocrlf=true, my tool is fighting against git. git shouldn't spend time converting to CRLF which is about to be converted back to LF by my tool.

That's why I set core.autocrlf=false, and ask git to normalize files to LF.

So the problem is that, conversion to LF is not happening.


```

## Lidong Yan, 2025-07-13 07:43

Subject: Re: Why doesn't git core.eol=lf work?
Message-ID: <C41F422E-8C9D-4BC7-BA0B-57B7D13D6557@gmail.com>
URL: https://gitlist.dev/e/C41F422E-8C9D-4BC7-BA0B-57B7D13D6557%40gmail.com
In-Reply-To: <sAxC2ASixUyCVtsk22zrxI2vAeM546T7O2tyWIS2vv_TGFo2OXWegg8J_r0zGzo5bZOA-BrwHa5yjAv2-Ewusjv9Fa9YYocrRkaIfpxhv_c=@proton.me>

```
Jason Cho <jason11choca@proton.me> write:
> 
>> 
>> Since you posted `git diff` output, may I ask if your concern is
>> actually the ^M in the diff output, which you intend to fix with
>> automatic CRLF-to-LF conversion?
>> 
> 
> No, my intent is to find moved or duplicated text among files. 
> 
> Let's say license_header.txt has 
> 
> DBeaver - Universal Database Manager^M
> Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
> 
> and another.txt has
> 
> DBeaver - Universal Database Manager
> Copyright (C) 2010-2018 Serge Rider (serge@jkiss.org)
> 
> My tool doesn't think the two pieces of txt the same because of ^M.
> 
> Although my tool can do normalization internally, if git checks out files to CRLF due to core.autocrlf=true, my tool is fighting against git. git shouldn't spend time converting to CRLF which is about to be converted back to LF by my tool.
> 
> That's why I set core.autocrlf=false, and ask git to normalize files to LF.
> 
> So the problem is that, conversion to LF is not happening.

I believe that it's impossible to check out CRLF from the index as LF.
You have to use your tool to do that.

The definition of core.eol=lf is here:
  https://git-scm.com/docs/gitattributes/2.9.5#:~:text=Set,-to%20string%20value%20%22lf

This means that when you use git add to stage files, Git will convert
CRLF line endings to LF. However, when you check out files, Git will
leave the line endings unchanged.

Thanks,
Lidong
```

## Jason Cho, 2025-07-13 14:08

Subject: Re: Why doesn't git core.eol=lf work?
Message-ID: <wzZi9r7E7j1avCRjH89z3cdSJnwdoam1xRulfmRkybAYRIGxmZeZCYqRALW-b0B2lKnZ8xnuoAjwpWpMeDAx2oSW4qnlmS8iuUKit3And6Q=@proton.me>
URL: https://gitlist.dev/e/wzZi9r7E7j1avCRjH89z3cdSJnwdoam1xRulfmRkybAYRIGxmZeZCYqRALW-b0B2lKnZ8xnuoAjwpWpMeDAx2oSW4qnlmS8iuUKit3And6Q%3D%40proton.me
In-Reply-To: <C41F422E-8C9D-4BC7-BA0B-57B7D13D6557@gmail.com>

```
> 
> 
> I believe that it's impossible to check out CRLF from the index as LF.
> You have to use your tool to do that.
> 
> The definition of core.eol=lf is here:
> https://git-scm.com/docs/gitattributes/2.9.5#:~:text=Set,-to string value "lf
> 
> This means that when you use git add to stage files, Git will convert
> CRLF line endings to LF. However, when you check out files, Git will
> leave the line endings unchanged.
> 

I see. Thank you so much. This detail was so subtle and it totally flew under my radar.


```
