I have the following definition of .gitattributes
:
*.sh text eol=lf
* text eol=crlf
if git works properly, it should reformat all *.sh
file under the current directory into using lf
as the only end-of-line.
Unfortunately, after running git add --renormalize .
, nothing happens.
How could this happen? Is git implementation buggy for this feature? If not, what is the correct command to enforce .gitattributes
?
When using your
.gitattributes
file in a test repo, I get repeated warnings each time I add a new file:*
refers to the second*
on your last line, when I change that line to* text eol=crlf
,git
correctly preserveslf
in.sh
files and turns mylf
intocrlf
in other files (I run on linux, withgit version 2.42.0
)I think your
.gitattributes
doesn't apply because it has an invalid content.Perhaps the error message isn't shown in your case -- for example, GUI clients sometimes hide the warning messages --, or perhaps older versions of git didn't warn explicitly about as many things.
I don't think saying "everything is a text file" is a good fix: it would mess with your binary files and tru to turn
\10
(=lf
) into\13\10
(=crlf
).You should either choose a more explicit list of things to consider as a text file, or drop that last line entirely and rely on git's default behavior.
If you have an ulterior motive to absolutely commit files with
crlf
in them, please explain in more details your requirements.