I tried committing files with CRLF-ending lines, but it failed.
I spent a whole work day on my Windows computer trying different strategies and was almost drawn to s
These are the two options for Windows and Visual Studio users that share code with Mac or Linux users. For an extended explanation, read the gitattributes manual.
In your repo's .gitattributes
file add:
* text=auto
This will normalize all the files with LF
line endings in the repo.
And depending on your operating system (core.eol
setting), files in the working tree will be normalized to LF
for Unix based systems or CRLF
for Windows systems.
This is the configuration that Microsoft .NET repos use.
Example:
Hello\r\nWorld
Will be normalized in the repo always as:
Hello\nWorld
On checkout, the working tree in Windows will be converted to:
Hello\r\nWorld
On checkout, the working tree in Mac will be left as:
Hello\nWorld
Note: If your repo already contains files not normalized,
git status
will show these files as completely modified the next time you make any change on them, and it could be a pain for other users to merge their changes later. See refreshing a repository after changing line endings for more information.
If text
is unspecified in the .gitattributes
file, Git uses the core.autocrlf
configuration variable to determine if the file should be converted.
For Windows users, git config --global core.autocrlf true
is a great option because:
LF
line endings only when added to the repo. If there are files not normalized in the repo, this setting will not touch them.CRLF
line endings in the working directory.The problem with this approach is that:
autocrlf = input
, you will see a bunch of files with LF
line endings. Not a hazard for the rest of the team, because your commits will still be normalized with LF
line endings.core.autocrlf = false
, you will see a bunch of files with LF
line endings and you may introduce files with CRLF
line endings into the repo.autocrlf = input
and may get files with CRLF
file endings, probably from Windows users with core.autocrlf = false
.