Last active
July 31, 2024 12:46
-
-
Save Bazsmagister/51abae5b661344d34223c4707dd001fb to your computer and use it in GitHub Desktop.
What does in .gitattributes * text=auto, and difference between CRLF and LF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Auto detect text files and perform LF normalization | |
* text=auto | |
In a .gitattributes file, setting `text=auto` means that the path is marked for automatic end-of-line normalization. | |
If Git decides that the content is text, its line endings are normalized to LF on check-in. | |
This setting allows fine-grained control over how line endings are converted. | |
https://stackoverflow.com/questions/21472971/what-is-the-purpose-of-text-auto-in-gitattributes-file | |
from that SO question: | |
" | |
Here's what * text=auto does in my words: when someone commits a file, | |
Git guesses whether that file is a text file or not, and if it is, | |
it will commit a version of the file where all CR + LF bytes are replaced with LF bytes. | |
It doesn't directly affect what files look like in the working tree, | |
there are other settings that will convert LF bytes to CR + LF bytes when checking out a file. | |
I would not recommend putting * text=auto in the .gitattributes file. Instead, I would recommend something like this: | |
*.txt text | |
*.html text | |
*.css text | |
*.js text | |
This explicitly designates which files are text files, | |
hich get CRLF converted to LF in the object database (but not necessarily in the working tree). | |
We had a repo with * text=auto, and Git guessed wrong for an image file that it was a text file, | |
causing it to corrupt it as it replaced CR + LF bytes with LF bytes in the object database. | |
That was not a fun one to debug. | |
If you must use * text=auto, put it as the first line in .gitattributes, so that the later lines can override it. | |
This seems to be becoming an increasingly popular practise. | |
" | |
CR vs CRLF | |
//Only Windows (considering main-stream OSs only) is using CRLF, Linux uses LF. | |
LF means Line-Feed. | |
CR means Carriage Return. | |
https://stackoverflow.com/questions/6521685/why-does-windows-use-cr-lf | |
from that SO question: | |
"Historically when using teletypes CR would return the carriage to the first position of the line | |
while LF would feed to the next line. | |
Using CR+LF in the file themselves made it possible to send a file directly to the printer, | |
without any kind of printer driver." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment