0

I share a git repository with many people and we are currently finding it difficult to get the desired line ending function. What we would like to happen:

  • All files on the repository are stored with LF line endings
  • When a Mac user pulls/clones/pushes, everything remains the same
  • When a Windows user pulls/clones, everything is converted to CRLF with the exception of .scr files
  • When a Windows user pushes, everything is converted to LF (see first bullet)

I've tried a couple different .gitattributes solutions and I think this can be done, I just haven't found the correct way to do.

WhS4
  • 83
  • 1
  • 1
  • 7

1 Answers1

0

This is often specific to the editor you use.

You can use a standardised set of rules like EditorConfig to specify common line endings. As long as everyone in your term uses an IDE that either supports it natively or has a plugin installed that supports it, you should be able to achieve cross platform consistency.

An stripped back .editorconfig file that specifies LF line endings might look like this:

# top-most EditorConfig file
root = true

[*]
end_of_line = lf

Some editors with support built in, and plugins for others are listed here.

scrowler
  • 24,273
  • 9
  • 60
  • 92
  • I have no way of ensuring that everyone uses the same IDE. In fact this will hopefully become a public project soon so I'm hoping to make it so that any user can pull the project without needing to make line ending adjustments themselves. – WhS4 Nov 22 '16 at 02:35
  • That's exactly the point of EditorConfig - it's cross platform and supported by most common IDEs. If the file exists and the user has the plugin installed, it will format your line endings the way you tell it to regardless of the IDE's configuration. If the user doesn't have EditorConfig support in their IDE and their line endings are configured to be something other than what you want, you won't be able to change that for them – scrowler Nov 22 '16 at 02:42
  • Ah I see now. Thank you for the answer and I'll definitely consider this, but I was hoping to do this through git only, not using an outside plugin. Is there no way to get the desired behavior through .gitattributes and git global config? – WhS4 Nov 22 '16 at 03:03
  • I'd assumed you had tried it and it wasn't working. Have you tried a `.gitattributes` file with `* text eol=lf` in it? – scrowler Nov 22 '16 at 03:05