英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论