4

I use git-svn at work and people are constantly complaining that I'm committing LF's instead of CRLF's. (We're mostly a Windows shop).

As far as I can tell, when core.autocrlf is true the working copy is CRLF, when false it's LF, and when input it's left untouched. I like the autocrlf = true as a concept, but I wish it would default to CRLF in the index since that's what get's committed to SVN.

Is there a way to set what line ending the index uses?

I've seen core.eol, but this also seems to only set what the working copy uses, not the index.

kelloti
  • 8,373
  • 4
  • 44
  • 78

2 Answers2

2

You'll want to add a file named .gitattributes to the root of your project. This will force everyone to commit same line ending. In you case, as you want to force crlf, you'll add this line in the .gitattributes:

* text eol=crlf

Then, you can also normalize every files in your repo once, and never bother about it again: Trying to fix line-endings with git filter-branch, but having no luck

You can also refer to github guide on line ending: https://help.github.com/articles/dealing-with-line-endings

Community
  • 1
  • 1
Simon Boudrias
  • 40,550
  • 15
  • 92
  • 129
  • Can I do this without a `.gitattributes` file? Maybe a `.git/info/attributes` file instead? (Since I'm using `git-svn`) – kelloti Feb 04 '13 at 18:26
  • Yes, you can also put this setting in this file and have the same effect (only for you). – Simon Boudrias Feb 04 '13 at 18:29
  • You can checkout the section on file precedence on the git documentation: http://www.kernel.org/pub/software/scm/git/docs/gitattributes.html – Simon Boudrias Feb 04 '13 at 18:30
  • ok, I'm having trouble with the `git diff ... | xargs...` line. It says `xargs: argument line too long`. I'm not sure I want to make that many changes anyway... – kelloti Feb 04 '13 at 18:34
  • 1
    I don't think this even answers the question - the docs say this is just like setting `core.autocrlf = true` but only on certain files (in this case only text files, so it's absolutely no different). – kelloti Feb 04 '13 at 18:39
  • By specifying `*`, you take every files. And by text files, they mean not `binaries` files, and not _only_ `*.txt`. Also, setting `autocrlf` to true will always commit files as ending in `lf`, that's why we manually set them to be `crlf`. – Simon Boudrias Feb 04 '13 at 18:41
  • 3
    For `eol=crlf` it says `This setting forces git to normalize line endings for this file on checkin and convert them to CRLF when the file is checked out.` To me this means that it's still normalizing to `LF` in the index (vague as it reads) and convert to `CRLF` in the working copy. But I want it to normalize to `CRLF` in the index. Is that even possible? – kelloti Feb 04 '13 at 18:49
  • You can test it out. `git diff` will point out if there's changes to the line-ending. If it's not working, then just set `core.autocrlf` to false and Git won't change line-ending anything automatically; this will work as long as every developer is on windows. – Simon Boudrias Feb 04 '13 at 19:06
  • It seems the person asking the question wants to store CRLF in the index. This does not do that. – Daniel Leach Oct 17 '17 at 19:09
1

It turns out that git-svn uses the svn:eol-style property from SVN to decide how to store the line endings. If you go into a pure SVN checkout & add svn:eol-style set to native, Git will use CRLF for Windows and LF for Linux/OSX.

I also have these settings:

$ git config core.autocrlf false
$ git config core.safecrlf true

I don't have anything in my .gitattributes file.

kelloti
  • 8,373
  • 4
  • 44
  • 78