windows平台下使用git add,git deploy 文件时经常出现“warning: LF will be replaced by CRLF” 的提示
Git 可以在你提交时自动地把回车(CR)和换行(LF)转换成换行(LF),而在检出代码时把换行(LF)转换成回车(CR)和换行(LF)。 你可以用 git config --global core.autocrlf true 来打开此项功能。 如果是在 Windows 系统上,把它设置成 true,这样在检出代码时,换行会被转换成回车和换行:
#提交时转换为LF,检出时转换为CRLF
$ git config --global core.autocrlf true
不知道你这个问题是否已经解决, 如果还没有解决的话:$ 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
$ 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
针对该问题,有以下几种解决方案:
直接忽略: 根据参考资料中的段落2,遇到这种问题可以直接忽略,不会对整体工作造成影响。如果只是一个警告,可以选择忽略。无需进行额外操作。
关闭自动换行符转换: 可以使用以下指令关闭自动换行符转换:
git config --global core.autocrlf false
这种方法已经在参考资料段落3中给出。
使用一个统一的换行符: 在项目中规定使用一个统一的换行符,这样就不会出现换行符错乱的问题。建议使用Unix的LF换行符。
使用Git LFS: Git Large File Storage (LFS)是一个Git扩展,允许您将大型二进制文件存储在单独的存储库中。Git LFS允许您将二进制文件存储在单独的 Git LFS 存储库中,而不是与代码在同一个存储库中。这样可以避免代码库过大,同时也方便管理。需要注意的是,LFS是面对企业级的收费项目,如果是个人使用可以选择一些免费的Git仓库。
以上是针对该问题的几种解决方案,可以根据具体情况进行选择。其中第二种方法是针对普遍情况的最优解决方案。