Reproduced from: http://blog.csdn.net/lysc_forever/article/details/42835203
When you encounter both of these errors, you are basically asking you to set Autocrlf to false. But I think it's very wrong.
If you have a line break in your source file and autocrlf=true, git add will encounter FATAL:LF would is replaced by CRLF error. There are two solutions:
1. Convert the LF in your source file to CRLF to "recommend"
2. Set Autocrlf to False
If you have a newline character in your source file that is CRLF and autocrlf=input, git add will also encounter an error Fatal:crlf would be replaced by LF . There are two solutions:
1. Convert the CRLF in your source file to LF "recommend"
2. Set Autocrlf to True or false
My suggestion: Set Autocrlf = input on the mac and set Autocrlf = True on Windows (default).
--------------------------------------------------------------------------------------------------------------- -------------------
In that case,
Windows: (True)
When submitting, turn CRLF into LF;
When it is cut out, the LF is automatically converted to CRLF;
Mac/linux: (Input)
When submitting, turn CRLF into LF;
When you cut out, keep LF.
This will ensure that the warehouse is always LF. And the Windows Workspace is CRLF, and the mac/linux work space is LF.
--------------------------------------------------------------------------------------------------------------- -------------------
Core.autocrlf
If you're writing a program on Windows, or you're working with someone else, they're programming on windows, and you're on another system, in which case you may experience a end-of-line end problem. This is because Windows uses a carriage return and a newline of two characters to end a row, while the Mac and Linux use only a newline character. While this is a minor problem, it can greatly disrupt cross-platform collaboration.
Git automatically converts the line terminator CRLF to LF when you submit, and converts LF to CRLF when the code is checked out. Use Core.autocrlf to turn on this feature, and if it is on a Windows system, set it to true so that if the code is checked out, the LF is converted to CRLF: [plain] view plain copy $ git config- Global Core.autocrlf True
Linux or Mac systems use LF as a line terminator, so you don't want Git to be automatically converted when you check out a file, and when a file with a CRLF is accidentally introduced, you want to fix it, and set the CORE.AUTOCRLF as input to tell Git Convert CRLF to LF at submit, not converted when checked out: [plain] view plain copy $ git config--global core.autocrlf input
This preserves CRLF in checked-out files on Windows systems, leaving LF in Mac and Linux systems, including warehouses.
If you are a Windows programmer and you are developing a project that runs only on Windows, you can set false to cancel this feature and record the carriage return in the library: [plain] view plain copy $ git config--global Core.autocrlf false
Windows returns to Linux or Unix
Find. -iname "*.java" | xargs-i FL Dos2unix FL
Linux return to Windows
Find. -iname "*.java" | xargs-i FL unix2dos FL