Windows system git newline problem

The line breaks of text files are different on different systems. Linux / MAC uses LF (\ n), but Windows uses CRLF (\ r \ n) as the line break.
The build, test, and production environments are generally code developed under the Linux environment and the Windows environment. When you submit the code to the Linux environment through git, you will encounter line breaks.

The premise is the default ide configuration, which is windows

Solution:
1) Generally, when git windows install, choose the following settings
Windows system git newline problem

2) After git windows is installed, you can configure the following two parameters:
git config --global core.autocrlf true
true means that the checkout is converted to CRLF, when converted to LF
input means that the checkout is not converted, and when converted to LF
false Means no conversion

git config --global core.safecrlf true
true indicates that different line breaks
are not allowed when submitting warn, only warns
when there are different line breaks, false allows different line breaks when price increases are allowed,
or can be modified by ~ / .gitconfig
[core ]
autocrlf = false ---> true
safecrlf = true



In order to further limit the problem of line breaks in team development (without the code submission set by git above), you can add .gitattributes in the git repo,

#Auto detect text files and perform CRLF--->LF normalization
* text=auto

reference

  1. GitHub first pit: automatic conversion of line breaks https://github.com/cssmagic/blog/issues/22

Guess you like

Origin blog.51cto.com/9483003/2486649