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 9, 2019, 03:34 UTC
Message-ID
<20190809033406.5t5ag3qmh36ideec@tb-raspi4>
In-Reply-To
<577a66e0c26545aaa4795de3c5189c9d@bofa.com>
On Thu, Aug 08, 2019 at 11:08:14PM +0000, Yagnatinsky, Mark wrote:
Show 23 quoted lines
> Okay, my attempt at better wording for the docs is not going well, because it turns I that I still don't understand the behavior here!
> I thought that "input" means that CRLF will become LF on "git add" but that seems to be true only sometimes.
> For instance, consider the following 11-line shell script:
>
> mkdir empty
> cd empty
> git init
> git config core.autocrlf false
> echo -e '1\r\n2' > test.txt
> git add .
> git commit -m test
> git config core.autocrlf input
> cp test.txt t2.txt
> echo 'a\r\nb' > test.txt
> git add .
>
> The output from the last git add is:
>
> warning: CRLF will be replaced by LF in t2.txt.
> The file will have its original line endings in your working directory.
>
> Which is a very good warning indeed, but why does it only apply to the new file t2.txt?
> Why does the existing file test.txt retain its CRLF line endings.
Because there are no CRLF ;-)

This line echo 'a\r\nb' > test.txt should probably be written as echo -e 'a\r\nb' > test.txt or better printf 'a\r\nb' > test.txt

> I am so confused.
Please run

od -c test.txt and may be git ls-files --eol

>
> Any pointers?
https://git-scm.com/docs/git-add

What happens if you run the following: mkdir empty cd empty git init echo "* -text" >.gitattributes printf '1\r\n2' > test.txt git add . git commit -m "Add test.txt with CRLF"

echo "* text=auto eol=lf" >.gitattributes cp test.txt t2.txt printf 'a\r\nb' > test.txt git add .

git commit -m "cp text.txt t2.txt; change test.txt; eol=input"

git add --renormailze test.txt git commit -m "Normalize line endings in text.txt"

Previous: Yagnatinsky, MarkNext: Yagnatinsky, Mark
Message 5 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.