Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 957
tribbloid Avatar asked Oct 15 '25 19:10

tribbloid


1 Answers

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.

like image 99
VonC Avatar answered Oct 18 '25 12:10

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!