Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project newlines and .gitattributes #903

Open
tbmatuka opened this issue Feb 7, 2022 · 2 comments
Open

Project newlines and .gitattributes #903

tbmatuka opened this issue Feb 7, 2022 · 2 comments

Comments

@tbmatuka
Copy link

tbmatuka commented Feb 7, 2022

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 😆

@matthewtrask
Copy link
Collaborator

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

@petk
Copy link
Contributor

petk commented Jan 17, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants