Git * text = auto in gitattributes file and line ending

Based on this post: What is the purpose of `text = auto` in the` .gitattributes` file? the end of the line is converted to LF for text files if the following is in the .gitattributes file:

* text=auto

I just tested this in a local repository:

$ git add -A
warning: LF will be replaced by CRLF in [bla]/.gitattributes.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in [bla]/.gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in [bla]/README.md.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in [bla].csproj.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in 

But it says that it converts to CRLF . The above message says that it converts to LF , which does not match this test.

So it seems that:

* text=auto

will be converted to the final OS-based line type (CRLF for Windows and LF for Linux). But this is not what is described here:

https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

/, , - :

* text=auto

.gitattributes:

warning: LF will be replaced by CRLF in [bla]/README.md.
The file will have its original line endings in your working directory.

, check- out ( ) , LF, CRLF.

, LF, :

https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

"auto" "", . Git , , LF .

+4
1

.

Git , . , Git CRLF ( ) - , , Git , , .

- Unix ( Unix Windows-). . , Unix:

C:\Temp>hexdump /C foo
00000000  68 65 6c 6c 6f 21 0a                              |hello!.|
00000007

( * text=auto core.autocrlf=true):

C:\Temp>git add foo
warning: LF will be replaced by CRLF in foo.
The file will have its original line endings in your working directory.

Git, (Unix-) :

C:\Temp>hexdump /C foo
00000000  68 65 6c 6c 6f 21 0a                              |hello!.|
00000007   

Unix:

C:\Temp>git ls-files --stage
100644 4effa19f4f75f846c3229b9dbdbad14eff362f32 0       foo

C:\Temp>git cat-file blob 4effa19 | hexdump /C
00000000  68 65 6c 6c 6f 21 0a                              |hello!.|
00000007

Git , - CRLF, :

C:\Temp>del foo

C:\Temp>git checkout -f foo

C:\Temp>hexdump -C foo
00000000  68 65 6c 6c 6f 21 0d 0a                           |hello!..|
00000008

, , , . , , , , .

+1

Source: https://habr.com/ru/post/1617080/


All Articles