I am programming on mac, and I don't really understand what Git does with the end of line of my files :
I created a repository with some files in Unix format (LF end of line).
When I clone the repository that I created, all my end of lines are CRLF. Shouldn't it detect automatically that I need LF end of line ?
I have autoclrf set to true.
GIT's documentation about autoclrf is pretty hard to understand :
If you simply want to have CRLF line endings in your working directory regardless of the repository you are working with, you can set the config variable "core.autocrlf" without changing any attributes.
[core]
autocrlf = true
This does not force normalization of all text files, but does ensure that text files that you introduce to the repository have their line endings normalized to LF when they are added, and that files that are already normalized in the repository stay normalized.
The first sentence says "if you want to have all crlf", when the second sentence says that git will auto-adjust the end of lines.
In my case, it seems like Git converts everything to CRLF and leaves it like that when I try to clone.
text eol=crlf Git will always convert line endings to CRLF on checkout. You should use this for files that must keep CRLF endings, even on OSX or Linux. text eol=lf Git will always convert line endings to LF on checkout. You should use this for files that must keep LF endings, even on Windows.
Once you select View > Show Symbol > Show End of Line you can see the CR LF characters visually. You can then use the menu item Edit > EOL Conversion and select Unix (LF). After selection Edit > EOL Conversion > Unix (LF) your file will be correct for submission.
LF. original (usually LF , or CRLF if you're viewing a file you created on Windows) Both of these options enable automatic line ending normalization for text files, with one minor difference: core. autocrlf=true converts files to CRLF on checkout from the repo to the working tree, while core.
The gitattributes manpage is poorly laid out. In a later section, you'll find:
The
core.eol
configuration variable controls which line endings git will use for normalized files in your working directory; the default is to use the native line ending for your platform, or CRLF ifcore.autocrlf
is set.
So, unless you've specified core.eol
, you'll end up with lines terminated by CR+LF characters regardless of whether you're using Apple Mac OS X, Microsoft Windows, or Ubuntu Linux.
From your question:
The first sentence says "if you want to have all crlf", when the second sentence says that git will auto-adjust the end of lines.
It's important to note that there are two directions of adjustment that get performed when core.autocrlf
is set to true
:
The first thing you'll want to do is to unset core.autocrlf
or set it to false
. If you then want checked out text files to conform to the user's OS-preferred line endings, regardless of how they were created, just add this to your .gitattributes:
* text=auto
Alternatively, if git's not good at guessing which of your files are text, you could declare a specific extension to undergo this two-way normalization:
*.ext text
(where ext
is the file extension in question)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With