php-the-right-way icon indicating copy to clipboard operation
php-the-right-way copied to clipboard

Project newlines and .gitattributes

Open tbmatuka opened this issue 3 years ago • 2 comments

Every project should have its newline settings defined in .gitattributes to avoid a mess of windows and unix newlines. There's an added benefit of using .gitattributes to simplify your git diff output by defining big generated files (for example composer.lock) as binary.

BTW this project doesn't have a .gitattributes file either :laughing:

tbmatuka avatar Feb 07 '22 09:02 tbmatuka

if you want to create one, we would accept the PR.

matthewtrask avatar Feb 07 '22 14:02 matthewtrask

Hello.

Newline characters:

  • LF (\n) (*nix and Mac)
  • CRLF (\r\n) (Windows)
  • CR (\r) (old Mac, obsolete)

To see which line endings are in the Git index and in the working copy the following command can be used: git ls-files --eol

  • First column is the Git index (which should be for this project all i/lf)
  • Second column is the working copy (which depends on your platform, for Windows there will be crlf, for *nix there will be lf)
  • Third column are attributes for the file.

Git additionally provides .gitattributes file to specify if some files need to have specific line endings on all platforms (either CRLF or LF).

Changed files shouldn't cause issues on modern Windows platforms because also Git can do output conversion if core.autocrlf=true is set on Windows and user have CRLF newlines in all files in the working tree.

Unless CRLF files are tracked specifically, Git by default tracks all files in the index using LF newlines. So, I wouldn't add a specific .gitattributes in this project regarding the new lines.

petk avatar Jan 17 '23 22:01 petk