core.autocrlf
1.如果为true,当从读文本文件时,git将行尾的CRLF转换为LF,写文件时进行相反的转换。
2.也可以设置为input,这种情况,只在读取文本文件是进行转换,在写文件时,将LF作为行尾结束符。
3.一个文件是否本认为是文本文件(也就是受到autocrlf机制的约束),依赖文件的crlf属性,或者,如果没有指定crlf属性,那么主要依赖文件的内容。
core.autocrlf 转换
如果core.autocrlf为false,不进行转换。(git config core.autocrlf false)
如果core.autocrlf为true,在工作路径中的文件用CRLF作为结束符,当提交(checkin)到代码库时,再转换为LF作为行结束符。
如果core.autocrlf被设置为input,在checkin时,行结束符被转换为LF,但是checkout时,则不会转换。
core.safecrlf
If core.safecrlf is set to "true" or "warn", git verifies if the conversion is reversible for the current setting of core.autocrlf. For "true", git rejects irreversible conversions; for "warn", git only prints a warning but accepts an irreversible conversion. The safety triggers to prevent such a conversion done to the files in the work tree, but there are a few exceptions. Even though…
-
git add itself does not touch the files in the work tree, the next checkout would, so the safety triggers;
-
git apply to update a text file with a patch does touch the files in the work tree, but the operation is about text files and CRLF conversion is about fixing the line ending inconsistencies, so the safety does not trigger;
-
git diff itself does not touch the files in the work tree, it is often run to inspect the changes you intend to next git add. To catch potential problems early, safety triggers.