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

huangapple go评论57阅读模式
英文:

How to apply `.gitattribute` file to all files under a directory?

问题

在一个任意的本地设置的 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

这个文件仅在 Git 提交新文件时才会被使用,这可能会导致许多碎片化的提交,这些提交除了特殊字符(特别是换行符)之外,不会改变文件内容。

哪个 Git 命令可以用来修改项目中的所有文件,而不管它们是否已提交?

英文:

In an arbitrary Git project set up locally, a .gitattribute file can be included in the root directory to control special characters depending on environments (using Apache Spark on GitHub as an example):

*.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

This file will only be used by Git when commiting new files, which may result in many fragmented commits that don't change file content except special characters (in particular, line separators).

Which Git command can I use to modify all files under a project in one run, regardless of whether it is committed?

答案1

得分: 4

如我在Git 2.16 (2018年第一季度)中提到的,您可以使用--renormalize选项应用更新后的.gitattributes指令:

git add --renormalize .

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

英文:

As I mentioned with Git 2.16 (Q1 2018), you can apply an updated .gitattributes directive with the --renormalize option:

git add --renormalize .

That would apply to all existing files, not just new files.

huangapple
  • 本文由 发表于 2023年6月6日 04:21:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76409757.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定