你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

【Cygwin64 Terminal】git 拉的代码提示:warning: LF will be replaced by CRLF

2022/1/1 12:19:50

前言

  • 如今windows操作系统占用的内存越来越大,导致自己想自己开发【操作系统】。。。
  • windows下安装【VM虚拟机】开发基于Linux的工程,感觉电脑内存吃不消
  • windows下可以使用【Cygwin64 】解决一部分问题

Cygwin64 本身也是问题

  • Cygwin64 由于工作在windows上,环境还是有区别与:Linux
  • windows下的文件名称,不区分大小写,按时Linux文件名区分大小写
  • windows 下的回车换行问题,最终发现是git 配置与拉代码引起的

git 正确的配置

  • windows下的git 配置如下:
#提交时转换为LF,检出时转换为CRLF
$ git config --global core.autocrlf true
#提交时转换为LF,检出时不转换
$ git config --global core.autocrlf input
  • 为何这么配置呢?这里是windows、Linux混合开发的场景下,回车换行问题突出,Linux下是sh文件,如果被自动增加\r,会造成各种异常的错误,无法正确的执行

问题如下

  • 一台电脑上,使用【Cygwin64】正常的 make menuconfig
  • 另一台电脑,git pull 代码后,发现各种错误,开始以为是Cygwin64没有安装全工具包,后面发现原来就是回车换行引起sh 文件无法正确运行引起的
$ git diff
warning: LF will be replaced by CRLF in .config.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .config.old.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .kconfig.d.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in include/autoconf.h.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in scripts/Kbuild.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in scripts/basic/.docproc.cmd.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in scripts/basic/.fixdep.cmd.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in scripts/basic/.split-include.cmd.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in scripts/gen_build_files.sh.
The file will have its original line endings in your working directory
  • 不要让 git 改变回车换行,也就是Linux 本身的回车换行,拉下来时 windows git 可以增加\r,但是提交时,不需要增加\r。
  • 以下大的错误,看似很多,就是 sh文件,被增加\r引起的。
$ make menuconfig
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/kxgettext.o
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/mconf
/cygdrive/d/github/pluto-os_hello/scripts/kconfig/lxdialog/check-lxdialog.sh: line 3: $'\r': command not found
/cygdrive/d/github/pluto-os_hello/scripts/kconfig/lxdialog/check-lxdialog.sh: line 5: syntax error near unexpected token `$'\r''
'cygdrive/d/github/pluto-os_hello/scripts/kconfig/lxdialog/check-lxdialog.sh: line 5: `ldflags()
/cygdrive/d/github/pluto-os_hello/scripts/kconfig/lxdialog/check-lxdialog.sh: line 3: $'\r': command not found
/cygdrive/d/github/pluto-os_hello/scripts/kconfig/lxdialog/check-lxdialog.sh: line 5: syntax error near unexpected token `$'\r''
'cygdrive/d/github/pluto-os_hello/scripts/kconfig/lxdialog/check-lxdialog.sh: line 5: `ldflags()
/cygdrive/d/github/pluto-os_hello/scripts/kconfig/lxdialog/check-lxdialog.sh: line 3: $'\r': command not found
/cygdrive/d/github/pluto-os_hello/scripts/kconfig/lxdialog/check-lxdialog.sh: line 5: syntax error near unexpected token `$'\r''
'cygdrive/d/github/pluto-os_hello/scripts/kconfig/lxdialog/check-lxdialog.sh: line 5: `ldflags()
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:31:10: error: #include expects "FILENAME" or <FILENAME>
   31 | #include CURSES_LOC

小结

  • 正确理解 git CRLF的配置问题
  • 注意Linux、windows混合开发过程中git的配置引起的问题
  • 注意Linux sh 文件不允许增加额外的:\r 的问题