Skip to content

Instantly share code, notes, and snippets.

@CruelDrool
Created September 8, 2023 18:12
Show Gist options
  • Save CruelDrool/8586148feb6f61b302f55ff57f21e49a to your computer and use it in GitHub Desktop.
Save CruelDrool/8586148feb6f61b302f55ff57f21e49a to your computer and use it in GitHub Desktop.
Testing EOL settings in .gitattributes.

Test1

Setup

Operating system: Windows 10

Settings

git core.autocrlf = true

.gitattributes file:

* text=auto eol=lf
*.bat eol=crlf
*.ps1 -text

Results

After pushing to remote:

File name Local EOL GitHub EOL
test.text CRLF LF
test.bat CRLF LF
test.ps1 CRLF CRLF

(Determining GitHub EOL was done by downloading the raw file and checking its EOL.)

After doing git rm -rf --cached . and git reset --hard HEAD:

File name Local EOL GitHub EOL
test.text LF LF
test.bat CRLF LF
test.ps1 CRLF CRLF

Conclusion

* text=auto eol=lf: text=auto - Git will auto-detect whether a file is text or binary. eol=lf - all text files, unless specified otherwise, will have LF as end-of-line upon checkout.

*.bat eol=crlf: Files will have LF on the remote repo, but CRLF on the local system.

*.ps1 -text: The text attribute is unset, which tells Git not to attempt any end-of-line conversion upon checkin/checkout; files will be as-is. This means that anyone can change the EOL on the remote repo, which may lead to inconsistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment