DEV Community

Discussion on: ELI5: The git error - 'CRLF would be replaced by LF in...'

Collapse
 
jsn1nj4 profile image
Elliot Derhay • Edited

Honestly, that message has always been confusing.

If you have git setup on Windows using Windows line endings (CRLF), I think you get that message when committing, right? You're getting that message because git has to convert between Windows line endings and Unix line endings (LF). It converts LF->CRLF on checkout, and CRLF->LF on commit. This only happens if your core.autocrlf setting is set to true (if I remember correctly).

CR and LF are 2 different whitespace characters. Older Macs used to use CR for line endings. Windows uses both combined, and Linux (and I believe newer Macs) uses LF.

Windows 10 now does support LF I think, and the code editors I've been using for years now supported LF before that (Atom, and now VS Code), so I try to stick with only LF these days. I've disabled core.autocrlf on my machine.

However, if you work with people who do use native Windows line endings, that is something everyone should be aware of when setting up git. This could even be configured per repository depending on weather most of your projects are collaborative or not. I'm usually the only one writing code where I work, so I get to make the rules. Lol

Collapse
 
hiboabd profile image
Hibo Abdilaahi • Edited

Thanks for taking the time out to write this detailed response! It’s nice to know others find it confusing too haha.

Yes you do get that message when committing and it prevents you from doing so. This explanation has helped me understand the error somewhat but I don’t see why I would get the message sometimes and not other times 😭 I think I need to keep a better eye on what I’m committing when the error happens which might shed some more light...

Thanks again!!

Collapse
 
jsn1nj4 profile image
Elliot Derhay • Edited

It may depend on whether there's a mix of line ending styles in a file. I haven't really looked into it myself. I just got sick of the warnings at some point and switched completely over to LF.

If I remember correctly, there may also be a way to completely disable warnings from Git. But I think it disables all of them, not just this one.

Happy to help when I can. Sorry I wasn't able to help resolve that specific issue.

Thread Thread
 
hiboabd profile image
Hibo Abdilaahi

Ahhh thanks I’ll look into switching for the future! No problem at all, you’ve already been helpful and I was able to easily get past the error. It’s just not the first time it’s happened so I’m wondering how to prevent it full stop, if possible.