[Git]多平台协作 忽略WhiteSpace

 
  1. git config --global core.autocrlf true

  2. git config --global core.safecrlf true

由于在不同的操作系统上对同一个项目进行开发,经常遇到因为回车编码不同导致文件明明没有修改却出现在modified files队列中,给Commit造成不便。 

虽然diff的时候可以方便的忽略空白,但是提交时仍然不便,这样设置后,提交前就会自动转换(具体见下),  Mark 一下。

Git has two modes of how it treats line endings:

$ git config core.autocrlf # that command will print either "true" or "false" 

You can set the mode to use by adding an additional parameter of true or false to the above command line.

If core.autocrlf is set to true, that means that any time you add a file to the git repo that git thinks is a text file, it will turn all CRLF line endings to just LF before it stores it in the commit. Whenever you git checkout something, all text files automatically will have their LF line endings converted to CRLF endings. This allows development of a project across platforms that use different line-ending styles without commits being very noisy because each editor changes the line ending style as the line ending style is always consistently LF.

问题:

设置autocrlf=true后,会遇到“warning: LF will be replaced by CRLF…..”的问题。(关于此问题,详见这里 http://blog.csdn.net/feng88724/article/details/11600375

原因:

The side-effect of this convenient conversion, and this is what the warning you’re seeing is about, is that if a text file you authored originally had LF endings instead of CRLF, it will be stored with LF as usual, but when checked out later it will have CRLF endings. For normal text files this is usually just fine. The warning is a “for your information” in this case, but in case git incorrectly assesses a binary file to be a text file, it is an important warning because git would then be corrupting your binary file.

If core.autocrlf is set to false, no line-ending conversion is ever performed, so text files are checked in as-is. This usually works ok, as long as all your developers are either on Linux or all on Windows. But in my experience I still tend to get text files with mixed line endings that end up causing problems.

My personal preference is to leave the setting turned ON, as a Windows developer.

参考: http://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/feng88724/article/details/11585011

猜你喜欢

转载自blog.csdn.net/aa1358075776/article/details/81156648