Under windows and under linux, git line break changes, ^M problem, git diff

 

Under windows and under linux, git line break changes, ^M problem, git diff

 

From:http://www.xuebuyuan.com/1390948.html

Windows uses CR LF to define newlines, and Linux uses LF. The full name of CR is Carriage Return, or expressed as \r, which means carriage return. The full name of LF is Line Feed, which is the real newline indicator. Why Windows adds a combined CR and LF representation is not clear to me. However, if you see the ^M character when using git diff, it means that the two files are different in line breaks.

For example, if I take a directory from my Windows development, I will find that almost all files have been modified. In fact, this is not the case, it is all caused by more CR files.

Here's a simple way to make git diff ignore newline differences:

git config --global core.whitespace cr-at-eol

A better way is to have a .gitattributes file for each project, with the settings for line breaks, refer to

https://help.github.com/articles/dealing-with-line-endings (me: this article is true)

 

From:http://www.cnblogs.com/qkhh/p/5212960.html

The development team develops under Windows and has IDE to manage the code. For us, it's better to disable the ability to convert newlines. I use cygwin to submit code, and always prompt automatic conversion characters when submitting. In fact, there is no need to submit, just run git status and see if there are any prompts.

Also found a circle on the Internet, some suggestions are to run the following command:

git config --global core.autocrlf false

git config --global core.saftcrlf true

If you don't run the command, it is the same to edit ~/.gitconfig directly and add the following:

[core]

    autocrlf = false

    safecrlf = true

But doesn't solve the problem. Later, I continued to look for it, and an article gave me a hint. Go to the project directory and find a .gitattributes file, put the first line of 

*text=auto !eof 

Change to *text=

That solved the problem. Running git status again no longer prompts for conversion.

Thanks to the people who shared it on the Internet with this gibberish, there is still a little less valuable sharing in Chinese now. 

 

From:http://blog.sina.com.cn/s/blog_64e1046201019yuh.html 

Line breaks are different on different platforms. For example, crlf is used for windows, and lf is used for mac or linux.

If the development platform is diverse, for example, programmer A is on windows, and programmer B is on mac or linux, then you need to use line breaks uniformly. Because of GIT on different platforms, newlines are automatically converted by default during checkout and commit. Therefore, you may find that sometimes you do not modify a file, but git prompts you to add and commit this file, because git automatically replaces the line break.

To avoid this, we need to set git not to automatically replace newlines.

1 Open the root directory of a repo and open .gitattributes

2 Find the * text=auto line, if you want to use the windows format uniformly, modify it to * text=crlf    

 If you want to use the linux format uniformly, modify it to * text=lf

3 After the modification, submit the modification to the .gitattributes file in the root directory

Off topic:

It is recommended to keep git's global newline automatic replacement settings, and only make specific settings for each repo.

 

 

+

+

+

=

+

+

+

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326219072&siteId=291194637