Skip to content

Instantly share code, notes, and snippets.

@kymtwyf
Created July 19, 2017 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kymtwyf/f56afff32e69e6dcea92bde2a5665a1b to your computer and use it in GitHub Desktop.
Save kymtwyf/f56afff32e69e6dcea92bde2a5665a1b to your computer and use it in GitHub Desktop.
Windows 下使用git的换行符问题, windows, CRLF, LF, git, .gitattributes

关于windows环境下CRLF line deliminator 的说明

  1. git 有一个config 叫core.autocrlf 如果设置为true的话, windows下git会在
  • checkout的时候把LF转换为CRLF (如果这时用eslint的linebreak-style进行较难的话会报错 message: 'Expected linebreaks to be 'LF' but found 'CRLF'. (linebreak-style)' )
  • push 的时候把CRLF转换为LF (这样保证服务器上还是LF)
  • 解决办法如2,3描述
  1. .gitattributes这个文件里面可以控制git在clone代码时对于line deliminator的转换 添加如下规则:
*.js text eol=lf

可将js文件保留LF换行,其他文件(如果在core.autocrlf=true)的情况下仍然会被转换为CRLF

3.针对windows下git 进行clone时,建议设置core.autocrlffalse

git config --global core.autocrlf false

然后再clone repository

注意:在windows下如果不使用CRLF的话,使用有些文本编辑器如Notepad的时候,代码会变成一行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment