How to express core.autocrlf = false with .gitattributes?
Asked Answered
E

1

24

This is amazing. With a gazillion posts on the Internet about core.autocrlf and .gitattributes I am still unable to figure out what to write in .gitattributes to express core.autocrlf = false

Can anyone clear the mist around it? I do not need all the fancy cases, just give me core.autocrlf = false in .gitattributes. Nothing more, but nothing less.

Ecotone answered 25/10, 2018 at 19:18 Comment(2)
Thanks for using .gitattributes! :DRiggs
There's actually several examples of this in git-scm.com/docs/gitattributes.Yarmouth
R
31

If you don't want line ending conversion on a file, set the -text attribute. To turn off conversion on all files, set:

* -text

Note that this doesn't mean "this file isn't text" - that would be the binary attribute - it means "don't do text manipulations (line ending changes) on it".

Riggs answered 25/10, 2018 at 19:36 Comment(8)
This is THE BEST thing you can do.... ever!!! Make it global, actually.Gomulka
No. Don't make it global. core.autocrlf is global, and that's the problem. Different people can have different settings. Line ending changes need to be per-repository (in .gitattributes), so that every contributor agrees.Riggs
Is there any special considerations if we also use Git LFS?Ecotone
@Ecotone No, git-lfs should work fine with this setup. (Any files tracked by git-lfs will also set -text for good measure.)Riggs
@EdwardThomson but line-ending mangling is bad. Text editors support whatever line ending on whatever operating system, and that's been true for a long time.Looseleaf
@Looseleaf I never said that line ending mangling was good. Despite that, there are some tools that expect line endings in a particular format (make and cmd jump immediately to mind)Riggs
@Looseleaf Try running a bash script that has CRLF. It's not "mangling" if it's fixing a problem.Posticous
@AlexDresko lots of shells work with arbitrary (or even inconsistent) line endings. If bash doesn't, I personally consider that a bug. Regardless, the whole point of this question/answer is to avoid setting it globally, and allow for old (or bad, or... cantankerous) tools that require specific line endings.Looseleaf

© 2022 - 2024 — McMap. All rights reserved.