[toc]

## 一、遇到的问题

#### (2) input

If you’re on a Linux or Mac system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:

### 2. core.safecrlf

If true, makes Git check if converting CRLF is reversible when end-of-line conversion is active. Git will verify if a command modifies a file in the work tree either directly or indirectly.For example, committing a file followed by checking out the same file should yield the original file in the work tree. If this is not the case for the current setting of core.autocrlf, Git will reject the file.

#### ^ _ ^ 使用dos2unix进行手动转换

find . -type f -print0 | xargs -0 dos2unix

dos2unix工具在Windows的MINGW64 Git Bash客户端上自带，在mac平台可以Google how to install dos2unix on mac，同理linux(sudo apt-get install dos2unix)，哈哈哈。

The variable can be set to "warn", in which case Git will only warn about an irreversible conversion but continue the operation.

CRLF conversion bears a slight chance of corrupting data. When it is enabled, Git will convert CRLF to LF during commit and LF to CRLF during checkout. A file that contains a mixture of LF and CRLF before the commit cannot be recreated by Git. For text files this is the right thing to do: it corrects line endings such that we have only LF line endings in the repository. But for binary files that are accidentally classified as text the conversion can corrupt data.
If you recognize such corruption early you can easily fix it by setting the conversion type explicitly in .gitattributes. Right after committing you still have the original file in your work tree and this file is not yet corrupted. You can explicitly tell Git that this file is binary and Git will handle the file appropriately.

Note, this safety check does not mean that a checkout will generate a file identical to the original file for a different setting of core.eol and core.autocrlf, but only for the current one. For example, a text file with LF would be accepted with core.eol=lf and could later be checked out with core.eol=crlf, in which case the resulting file would contain CRLF, although the original file contained LF. However, in both work trees the line endings would be consistent, that is either all LF or all CRLF, but never mixed. A file with mixed line endings would be reported by the core.safecrlf mechanism.

### 3. core.eol

Sets the line ending type to use in the working directory for files that have the text property set when core.autocrlf is false. Alternatives are lfcrlf and native, which uses the platform’s native line ending. The default value is native. See gitattributes[5] for more information on end-of-line conversion.
core.autocrlffalse，设置行结束符的类型，可以是

• lf
• crlf
• native三种，其中native是指平台默认的行结束符。默认的类型是native

## 六、总结一下吧

### 1. 不安全不保险的方式

git config --global core.autocrlf false
git config --global core.safecrlf false

### 2. 个人推荐的设置方式

#### （2）safecrlf设置为true

git config --global core.safecrlf true

#### （3）autocrlf在不同平台不同设置

• Windows
git config --global core.autocrlf true
• Mac Or Linux
git config --global core.autocrlf input

#### 补充

##### 第一点 Git Setup Treat Line Endings In Text Files

Git默认的core.autocrlf其实在安装Git For Windows的时候，让我们选择了，只是安装的时候并不会注意，就是下面这张图：