Article table of contents
- 1. Problems
- 2. Problem Analysis
- 3. Solutions
- Fourth, problem thinking
1. Questions
When performing git add on the windows platform, the console prints a warning warning: in the working copy of XXX.py’, LF will be replaced by CRLF the next time Git touches it
2. Problem Analysis
Dos/Windows platform default line break: carriage return (CR) + line feed (LF), i.e. ‘\r\
‘
Mac/Linux platform default newline: newline (LF), i.e. ‘\
‘
Enterprise servers are generally managed by Linux systems, so there is a need to replace line breaks
3. Solutions
Setting method one:
#Convert to LF when submitting, and convert to CRLF when checking out git config --global core.autocrlf true
*Applicable to Windows system, and is generally the default setting of Windows, will perform CRLF – LF conversion for newlines when submitting, and LF – CRLF conversion when checking out.
Setting method two:
#Convert to LF when submitting, not when checking out git config --global core.autocrlf input
*For Linux systems, all newlines are converted to CRLF to LF, but not converted back to CRLF when manipulated.
Setting method three:
#Submission and checkout are not converted git config --global core.autocrlf false
*Applicable to Windows system and only developed on Windows. CRLF/LF newlines are not converted on commit, checkout
Safecrlf check on file commit:
#Reject submission of files containing mixed newlines git config --global core.safecrlf true #Allow submission of files containing mixed newlines git config --global core.safecrlf false #Warn when submitting a file containing mixed newlines git config --global core.safecrlf warn
4. Problem thinking
- Cross-platform files have compatibility issues. Why is there LF-CRLF conversion only when the core.autocrlf parameter is set to true and checked out?
Having problems seeing cross-platform documentation:
· Linux files are displayed on one line under Windows.
· Windows files may end with an extra ^M symbol under LinuxThen there are the following possibilities:
① Windows does not use this function because the visual interface is better, the operation is simple, and the file format has no great influence on the daily operation.
② When Git’s pull and other functions pull files locally, they will operate based on the checkout configuration, so just set core.autocrlf to true.