Is there a way to enforce core.autocrlf=input
from within the .gitattributes
in order to propagate the policy throughout my colleagues?
In deta
It isn't clear exactly what you mean by "as is" in the working tree. If you want Git to store line endings in LF in the repository and let the user decide what they want in the working tree (based on their platform and/or settings), then use this:
* text
That will force line ending conversion on, and Git will convert files to LF in the repository and will honor the user's preferred line endings on checkout. If not all of your files are text (i.e., you have images or other binaries) and you'd like Git to guess, then you can use this:
* text=auto
Note that as mentioned by LoopInFool, this will not cause files that are already CRLF to be converted, so you'll need to be sure that your files are already in LF in the repository, or list those files types explicitly as text (e.g., *.c text
).
The behavior of core.autocrlf=input
is to force conversion to LF on addition into the repository and not to perform any conversion on checkout; that is, to always use LF endings regardless of the user's settings. If that's the behavior you want, then you can do that with the following:
* eol=lf
Note that setting eol
effectively sets the text
attribute, so you should not set it on any files that are binary.
If what you want is for Git to match the line endings that are already in the working tree on checkout (e.g, by reading the file), then it won't do that. Git always does line ending conversions based on configuration without regard to what's already there, so the user will have to indicate their preference in some way or accept the platform default behavior.
In addition, Git always counts any modification to the file size as a modification in git status
, even if it ignores those changes on add (say, because you've only changed line endings); this is similarly not avoidable.
If what you want is something entirely different, please go into a little more detail about what behavior you want, and I'll update with more details.