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

Re: suggestion for improved docs on autocrlf

From
Torsten Bögershausen <tboegi@web.de>
Date
Aug 11, 2019, 12:10 UTC
Message-ID
<20190811121004.guygurnopwwggvsp@tb-raspi4>
In-Reply-To
<0c1b48c9fad641689ead69fdd9f72d63@bofa.com>
On Fri, Aug 09, 2019 at 03:34:05PM +0000, Yagnatinsky, Mark wrote:
> After correcting spelling of renormalize, the end result of the script you gave is that line endings in working directory are CRLF,
> and in the repo are LF.
> Is that expected?
Yes. "git add" does typically not touch the files on disk at all.
> Surprising?

May be. Typically the CRLF is done in the .gitattributes file, which is commited and pushed/pulled between the different machines. In opposite, core.autocrlf is just local, and different contributors may use different settings, leading to all kind of CRLF frustrations.

Having said that, the .gitattributes file is established early in the lifetime of a project (=repo). I typically set up the .gitattributes file as the first commit, before adding any other files.

If, however, the .gitattributes file is added to a repo later (better late than never), and the developer messes it up for some reasons, then the original files are still in the working tree on disk.

Correcttions can be made after looking at 'git ls-files --eol' or other diagnostics.

>Not sure what you were trying to test there.
There ? I probably lost the script.
Show 23 quoted lines
>I also fixed my script to use printf, new version is:
> (using copy/paste this time, instead typing from memory like last time; learned my lesson).
>
> mkdir empty
> cd empty
> git init
> git config core.autocrlf false
> printf '1\r\n2' > test.txt
> git add .
> git commit -m test
> git config core.autocrlf input
> cp test.txt t2.txt
> printf 'a\r\nb' > test.txt
> git add .
>
> Thank you for ls-files, I've been resorting to deleting from working directory and then doing a checkout.
> And also thank you for the gem of "od -c"!
> The output of ls-files after running my script is:
>
> i/lf    w/crlf  attr/                   t2.txt
> i/crlf  w/crlf  attr/                   test.txt
>
> So I'm still confused.  Why didn't test.txt lose its CRs while t2.txt did?

This is because the "auto" feature does not change the line endings, when a file had been commited with CRLF. They may be there on purpose, or not. Git can not make this decision - the user can.

This is why we have 'git add --renormalize".
Previous: Yagnatinsky, MarkNext: Yagnatinsky, Mark
Message 7 of 23 in “suggestion for improved docs on autocrlf”
  1. Yagnatinsky, MarkAug 7, 2019
  2. Torsten BögershausenAug 8, 2019
  3. Yagnatinsky, MarkAug 8, 2019
  4. Yagnatinsky, MarkAug 8, 2019
  5. Torsten BögershausenAug 9, 2019
  6. Yagnatinsky, MarkAug 9, 2019
  7. Torsten BögershausenAug 11, 2019
  8. Yagnatinsky, MarkAug 12, 2019
  9. Junio C HamanoAug 12, 2019
  10. Yagnatinsky, MarkAug 12, 2019
  11. Torsten BögershausenAug 12, 2019
  12. Yagnatinsky, MarkAug 12, 2019
  13. Junio C HamanoAug 12, 2019
  14. Yagnatinsky, MarkAug 12, 2019
  15. Torsten BögershausenAug 13, 2019
  16. Yagnatinsky, MarkAug 13, 2019
  17. Torsten BögershausenAug 13, 2019
  18. Yagnatinsky, MarkAug 13, 2019
  19. Yagnatinsky, MarkAug 14, 2019
  20. Yagnatinsky, MarkAug 15, 2019
  21. Torsten BögershausenAug 16, 2019
  22. Yagnatinsky, MarkAug 16, 2019
  23. Junio C HamanoAug 13, 2019

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.