Skip to content
On this page

不同系统下换行符CRLFLF

linuxmacOS默认为LF(\n),而window默认为CRLF(\r\n)

查看git配置:git config -l

vscode右下角可查看当前文件换行符的格式

gitcore.autocrlf设置不同值时:

  • true 提交时将CRLF转化为LF,检出时将LF转化为CRLF

  • fasle 不做处理

  • input 提交时将CRLF转化为LF,检出时不做处理

衍生问题

  • git出现LF will be replaced by CRLF in xxx

  • Delete ␍ eslint(prettier/prettier)

解决方案:统一使用LF

  • git config core.autocrlf false

  • vscode设置中搜搜files.eol,设置为\n(LF)

  • vscode安装EditorConfig for VS Code,项目中新增.editorconfig文件,写入

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
# lf, cr, or crlf
end_of_line = lf
  • vscode设置中搜索@ext:esbenp.prettier-vscode设置end of lineLF

参考文档:

https://prettier.io/docs/en/options.html#end-of-line

http://www.kehuanxianshi.com/work/miniapp/miniapp-prettier-vscode.html

https://www.zhihu.com/question/50862500