Most active commenters
  • Kwpolska(3)

←back to thread

422 points km | 11 comments | | HN request time: 0.473s | source | bottom
1. 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 #
2. nsnshsuejeb ◴[] No.41831938[source]
The letters after the dot in my filename don't map 1 to 1 with the file format.
3. 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 #
4. zulu-inuoe ◴[] No.41832761[source]
3000% agree. I have been bitten endlessly by autocrlf. It is absolutely insane to me that anyone ever considered your having your SOURCE CONTROL tool get/set different content than what's in the repo
5. 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 #
6. dwattttt ◴[] No.41833488{3}[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 #
7. djha-skin ◴[] No.41836850[source]
Sure, don't use autocrlf. But some _windows_ tools need crlf, like for powershell or batch build scripts. Defaulting to lf in the editor will not save you.

Don't use `auto`, full marks, but the gitattributes file is indispensable as a safety net when explicit entries are used in it.

I mean, the whole point of the file is not everyone who is working on the project has their editors set to lf. Furthermore, not every tool is okay with line endings that are not CRLF.

When used properly (sure, ideally without auto), the git attributes file as a lifesaver.

replies(2): >>41841607 #>>41852346 #
8. psd1 ◴[] No.41841607{3}[source]
Powershell doesn't care about line endings, and hasn't since 2006 when v2 was launched. I have never seen v1 installed but
9. Kwpolska ◴[] No.41852346{3}[source]
When LF doesn’t work (e.g. in cmd), you can always use something like .editorconfig to tell editors to use CRLF, and you should keep those files as CRLF in the repo.
10. Kwpolska ◴[] No.41852375{3}[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.
11. layer8 ◴[] No.41852871{4}[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.