Search code examples
windowsgitend-of-line

End-of-Line Behavior and Git


I am new to Git. I've used GitHub a little before, but I quite recently started using Git itself locally on my system for version control.

I am on a Windows system. However, I'm working with some files originally created on a Mac. As such, whenever I stage files, I get the following warning:

warning: LF will be replaced by CRLF in contact.html. The file will have its original line endings in your working directory

Now, every previous question I've found on this topic is essentially just a bunch of people explaining the purpose of setting (core.autocrlf = true) over and over. The man pages are quite clear that on a Windows system, 'true' should lead to CRLF in the working directory, but all commits will be converted to LF in the repo. I get that.

1) Why is this message so terribly worded. It sounds backwards. The original line endings (at least initially) were LF. That should not be in my working directory. It sounds as if it is assuring me that it will remain LF in the working directory, but be CRLF in the repo. The opposite of what I want.

2)Assuming that 'core.autocrlf=true' gives me the behavior that I want (LF in repo ---- CRLF in working copy). How do I disable this terribly confusing message so that I don't see it every time I 'git add'? It creates a lot of visual clutter if I'm working on multiple files.


Solution

  • This message means that you have files in your working tree that have a LF ending. That makes sense, since they were created on a Mac, and all modern versions of macOS use LF endings. However, if you commit them and then check them out, you will end up with CRLF line endings, since you're on Windows and have core.autocrlf set. That's what the message means. The LF endings in your working tree will be replaced next time the file is checked out for any reason.

    The idea, at least in principle, is to warn you that your line endings won't be preserved in case that matters to you. Maybe you're working with a shell script, and even on Windows, the shell requires LF endings. So you'd want to add an entry to .gitattributes.

    It also helps warn you if you're doing something with a binary file where line ending conversion would result in corruption. After all, your fancy JPEG image won't work as well if you change all of its 0x0a and 0x0d bytes.

    You can turn this warning off if you want by setting core.safecrlf to false.