←back to thread

422 points km | 4 comments | | HN request time: 0.001s | source
Show context
djha-skin ◴[] No.41831122[source]
> Let's make CRLF one less thing that your grandchildren need to know about or worry about.

The struggle is real, the problem is real. Parents, teach your kids to use .gitattribute files[1]. While you're at it, teach them to hate byte order marks[2].

1: https://stackoverflow.com/questions/73086622/is-a-gitattribu...

2: https://blog.djhaskin.com/blog/byte-order-marks-must-diemd/

replies(2): >>41831938 #>>41832500 #
Kwpolska ◴[] No.41832500[source]
Nope. Git should not mess with line endings, the remote repository not matching the code in your local clone can bite you when you least expect it. On Windows, one should disable the autocrlf misfeature (git config --global core.autocrlf false) and configure their text editor to default to LF.
replies(3): >>41832761 #>>41833176 #>>41836850 #
1. layer8 ◴[] No.41833176[source]
This is impractical in many situations, because tools that process build-source files (for example XML files that control the build, or generated source files) inherently generate CRLF on Windows. These are many, many, many tools, not just one’s text editor.

The correct solution is to use .gitattributes.

replies(2): >>41833488 #>>41852375 #
2. dwattttt ◴[] No.41833488[source]
If you're using tools that only support one particular line ending, the solution isn't to convert your source automatically in the repo, it's to know your source is always stored in one format, and convert it back/forth when a tool needs it to be different.

How would you handle two different tools only supporting disjoint line endings?

replies(1): >>41852871 #
3. Kwpolska ◴[] No.41852375[source]
If everyone’s on Windows, or if the tool always generates/requires CRLF, then you should store the files with CRLF line endings in the repository. In a mixed Windows/Linux environment, I would still prefer to handle this myself rather than expecting Git to mangle line endings.
4. layer8 ◴[] No.41852871[source]
The tools generally don’t care about the line endings on input, but they do generate their output using the platform’s line endings. If you don’t normalize the line-endings upon commit, then using the tools on Unix and Windows will alternatingly switch the line endings in the repo between LF and CRLF. And you don’t want to have those constant changes in your history and in the diffs.

Having Git normalize line endings for the relevant file types upon check-in is by far the simplest solution to this problem, in particular since having .gitattributes in the repository means that all clients automatically and consistently perform the same normalization.