Git 在 Windows 上检查具有 LF 行结尾的特定文件类型
Git check out a specific file type with LF line endings on Windows
在 Windows,我想查看所有 linux shell 具有 LF 行结尾的文件 (.sh)
其他基于文本的文件的行尾应转换为 CRLF。 (通过全局 core.autocrlf=true 处理)
- 全局.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。
附加信息:我的一名团队成员确实在一些提交之前更改了他的全局 core.autocrlf=false,我猜这导致了混乱的行结尾。
通过上述步骤,我至少可以修复本地存储库的文件,使其再次具有 CRLF 结尾。
尝试的步骤:
- 在本地删除文件并再次签出:无影响 - 所有 CRLF
- 删除文件、推送删除、使用 LF 重新创建文件:结帐后仍为 CRLF
- 使用 Notepad++ 手动更改行尾...
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
文件名有错字
尽管如此,解决方案:
修复 .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 的文件的行结尾
在 Windows,我想查看所有 linux shell 具有 LF 行结尾的文件 (.sh)
其他基于文本的文件的行尾应转换为 CRLF。 (通过全局 core.autocrlf=true 处理)
- 全局.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。
附加信息:我的一名团队成员确实在一些提交之前更改了他的全局 core.autocrlf=false,我猜这导致了混乱的行结尾。
通过上述步骤,我至少可以修复本地存储库的文件,使其再次具有 CRLF 结尾。
尝试的步骤:
- 在本地删除文件并再次签出:无影响 - 所有 CRLF
- 删除文件、推送删除、使用 LF 重新创建文件:结帐后仍为 CRLF
- 使用 Notepad++ 手动更改行尾...
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
文件名有错字
尽管如此,解决方案:
修复 .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 的文件的行结尾