Solve the Problem of git crlf linefeed, gitcrlf linefeed
Problem:
You are about to commit CRLF line separators to the Git repository.
It is recommended to set the core. autocrlf Git attribute to input and avoid line separator issues.
Problem description:
The project team now uses git for version control. In this case, we encounter different linefeeds on different platforms. In windows, the linefeeds are crlf, and in linux and max OS, the linefeeds are lf. For linux and MAX OS, set '''core. autocrlf input ''' (which seems to be the default value) and '''core. autocrlf true ''' in windows '''. However, sometimes you may encounter line breaks. In the review, we will find that all rows are deleted and rebuilt due to some changes in commit.
Set core. autocrlf in git
If you are writing a program on Windows, or you are working with others, they are programming on Windows, but you are on other systems, in which case, you may encounter an ending character at the end of a line. This is because Windows uses carriage return and line feed to end a line, while Mac and Linux only use a line break. Although this is a small problem, it will greatly disrupt cross-platform collaboration.
① Git can automatically convert the line terminator CRLF to LF upon submission, and convert the line terminator LF to CRLF when checking out the code. Use 'core. autocrlf 'to enable this function. If it is on a Windows system, set it to 'true', so that when the code is checked out, LF will be converted to CRLF:
$ Git config -- global core. autocrlf true
② Linux or Mac systems use LF as the line terminator, so you do not want Git to perform automatic conversion when checking out the file; when a file whose line terminator is CRLF is accidentally introduced, you must modify the 'core. autocrlf 'is set to input to tell Git to convert CRLF to LF at commit, but not at checkout:
$ Git config -- global core. autocrlf input
In this way, CRLF will be retained in the checkout file on Windows, and LF will be retained in Mac and Linux systems, including warehouse.
③ If you are a Windows programmer and are developing a project only running on Windows, you can set 'false' to cancel this function and record the carriage return in the Library:
$ Git config -- global core. autocrlf false
Solution 1. Modify git to set core. autocrlf = input. Do not convert when checking out, submit to lf, this can avoid submitting windows line breaks;
2. Modify eclipse settings windows> General> new text file line delimiter In workspace to select Unix.
3. There may be issues with line breaks in existing projects that need to be fixed.
If the current development has multiple branches and the branches are not synchronized, a conversion is required for each branch: select the Project file> convert line delimiter to> Unix to create a new commit;
If only one or more branches are on the same node. You can switch from the master to a new branch, perform Step 1 modification, and then commit to merge the branch to all branches.
4. push the modified branch to gitlab, and other Members can update the code.
(Ps: because each user's system is different or git is faulty, the line breaks may remain unchanged after the code is updated. In this case, reclone the latest code based on the code on the server)