Git在Windows上签出带有LF行尾的特定文件类型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git在Windows上签出带有LF行尾的特定文件类型相关的知识,希望对你有一定的参考价值。

在Windows上,我想签出所有带有LF行尾的linux shell文件(.sh)

其他基于文本的文件的行尾应转换为CRLF。 (通过全局core.autocrlf = true处理)

  • global .gitconfig

[core] editor = 'C:/Tools/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin autocrlf = true

  • 。gitattributes在存储库根文件夹中

*.sh text eol=lf

[添加.gitattributes文件时使用了git add --renormalize .

不幸的是,.sh文件在签出后仍然具有CRLF。


[附加信息:我的团队成员之一确实更改了他的全局核心。autocrlf= false,一些提交之前,我想这导致混乱的行结尾。

通过上述步骤,我至少可以修复本地存储库中的文件以使其再次具有CRLF结尾。


尝试的步骤:

  • 在本地删除文件并再次检出:无影响-全部CRLF
  • 删除文件,推送删除,使用LF重新创建文件:结帐后仍为CRLF
  • 手动使用记事本++更改行结尾...

user@workstation MINGW64 /c/repos/project-source (bug_sh_files_eol_lf) $ git status On branch bug_sh_files_eol_lf Your branch is up to date with 'origin/bug_sh_files_eol_lf'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: production_code/build_production_code.sh modified: test_code/unit_tests/create_unit_test_xml.sh no changes added to commit (use "git add" and/or "git commit -a") user@workstation MINGW64 /c/repos/project-source (bug_sh_files_eol_lf) $ git add . -u warning: LF will be replaced by CRLF in production_code/build_production_code.sh. The file will have its original line endings in your working directory warning: LF will be replaced by CRLF in test_code/unit_tests/create_unit_test_xml.sh. The file will have its original line endings in your working directory user@workstation MINGW64 /c/repos/project-source (bug_sh_files_eol_lf) $ git status On branch bug_sh_files_eol_lf Your branch is up to date with 'origin/bug_sh_files_eol_lf'. nothing to commit, working tree clean user@workstation MINGW64 /c/repos/project-source (bug_sh_files_eol_lf)

答案

没关系,我在.gitattributes文件名中输入错误:-|

尽管如此,解决方案:

  • fix .gitattributes

# normalize all introduced text files to LF line endings (recognized by git) * text=auto # additionally declare text file types *.sh text eol=lf *.c text *.h text *.txt text *.yml text

  • 称为“ git add --renormalize”。用资源库中的CRLF修复文件的行尾]

以上是关于Git在Windows上签出带有LF行尾的特定文件类型的主要内容,如果未能解决你的问题,请参考以下文章

如何更改行尾设置

从 Windows 批处理 (.bat) 脚本中回显带有 Unix 行尾的文本

windows下如何强制git使用LF而不是CR+LF?

git rebase 删除仅包含行尾更改的提交

使用远程 Git 签出存储库运行 eclipse

Git中出现 "LF will be replaced by CRLF" 警告