3

I am researching the best autocrlf setting for GIT and I am confused about what happens with code pasted into the editor if it is set to false. I notice many people recommend setting it to false, mentioning that as long as proper and properly set editors are used then there should be no problems, and I can understand this if I write ALL the code in the file; but I am confused about how this setting would work if I copy a snippit from eg a browser, or maybe some old code or something, or what if i used an entire old file. Surely I could easily end up with mixed CRLF and LF's as some of the code I get might be CRLF and some LF? Or are editors so smart that they themselves convert any pasted in code on save?

EDIT:I suppose I should also be asking: Is it a real problem if the EOF's are mixed?

byronyasgur
  • 4,627
  • 13
  • 52
  • 96
  • To me, this is entirely an editor question. If your editor is sane, it's not going to let you save with mixed line endings, or it's going to make it really obvious that you're trying to, and you can fix it. – Cascabel May 14 '12 at 01:35
  • Sorry could you clarify for me, the two situations I am thinking of are A)where I open up a file that is in CRLF but my editor is set to LF and B)where I am writing in an editor again set to LF but I copy and paste in some CRLF code from somewhere else, that in both situations the final saved file would be LF throughout? – byronyasgur May 14 '12 at 02:21
  • You should know what kind of line endings you want to be saving, and have your editor set up to help you do so. – Cascabel May 14 '12 at 03:17

1 Answers1

1

The idea is, in order to avoid any issue with EOF, to use only editors:

  • able to detect the current EOF style used by the opened file
  • able to save that file with the same EOF style (so, no conversion on save)

That way:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So by 'you don't care because your editor will always "do the right thing"' does that mean that a proper text editor properly set will figure out mixed CRLF's and LF's somehow ... that's what I meant by 'convert on save' – byronyasgur May 13 '12 at 23:16
  • Sorry, every time I read this stuff I get a new angle ... now I'm thinking that by that statement you mean that it doesn't really matter if the overall project actually contains mixed EOF throughout the files as long as every developer is using, for example, notepad++ ... but I thought the whole point of the 'true' and 'input' settings was to create consistency of EOF throughout all the code in the repo to avoid merge conflicts, but unless I'm reading you wrong, you're suggesting that's not the case and that consistent EOF's are only there to facilitate bad or wrongly set editors. – byronyasgur May 14 '12 at 00:55
  • @byronyasgur Only one angle should be clear: Ideally, mixed EOL shouldn't matter, ie your editor shouldn't perform any changes when editing or saving a file. – VonC May 14 '12 at 05:54
  • @byronyasgur "you're suggesting that's not the case and that consistent EOF's are only there to facilitate bad or wrongly set editors": no because if your files are all with Unix-style EOL and you edit them with a "bad" editor, you will get them with Windows-style EOL anyway. It would be best to use a "good" editor in the first place. – VonC May 14 '12 at 05:56
  • thanks for your patience, I should probably just trust you and use 'false' and a good editor and get on with it but what I cant understand is that if a good editor makes no changes to a file which contains both CRLF and LF ... and then git is set not to make any changes ... then that must mean we end up with mixed EOF in the files ... so what are the true and input settings for, if not to keep consistent EOF, but you say mixed EOF doesn't matter if everyone is using a good editor, so I conclude ( wrongly I presume?) that those settings must be solely to allow for people using bad editors – byronyasgur May 14 '12 at 11:29
  • @byronyasgur I didn't realize you were talking about mixed EOL within one file. I never had any issue with this case, but that can vary from project. The setting is more to make sure one consistent EOL is used for all the file, no matter the editor. What I recommend is to leave the EOL alone, even if they are mixed, unless that is proven to be an issue in your specific project. – VonC May 14 '12 at 12:07
  • yes that's my original question really, what If i paste some CRLF code into a LF file. I do a fair bit of copying and pasting for various reasons. Does it not make any difference really? – byronyasgur May 14 '12 at 12:13
  • @byronyasgur I didn't have any issue before with that kind of copy-paste with mixed EOL before, because my editors (like for instance Notepad++) leaves those EOL untouched. Unless you see a specific side-effect, you can ignore those EOLs. – VonC May 14 '12 at 13:11