如何将`.gitattribute`文件应用到目录下的所有文件?

tri*_*oid 4 git newline gitattributes core.autocrlf

在本地建立的任意Git项目中,.gitattribute根目录下可以包含一个文件来根据环境控制特殊字符(以GitHub上的Apache Spark为例):

*.bat text eol=crlf
*.cmd text eol=crlf
*.java text eol=lf
*.scala text eol=lf
*.xml text eol=lf
*.py text eol=lf
*.R text eol=lf
Run Code Online (Sandbox Code Playgroud)

Git 仅在提交新文件时使用此文件,这可能会导致许多碎片提交,这些提交不会更改除特殊字符(特别是行分隔符)之外的文件内容。

我可以使用哪一个 Git 命令一次性修改项目下的所有文件,无论是否提交?

Von*_*onC 5

正如我在 Git 2.16 (Q1 2018) 中提到的,您可以使用.gitattributes以下命令应用更新的指令--renormalize选项应用更新的指令:

git add --renormalize .
Run Code Online (Sandbox Code Playgroud)

这将适用于所有现有文件,而不仅仅是新文件。