3

Theoretically it is said that when working in a windows machine, people should use core.autocrlf set to true.

My windows machine git config settings is core.autocrlf=true

However when I clone a gitlab repository I can see that some sh files have their lines finished in \r.

(I do that by doing cat -A thefile.sh).

This originates all kinds of problems when I copy these files to a linux environment and try to run them.

For reference I cloned the same gitlab repo in a linux machine (where that configuration is not set) and the sh files have no \r in them.

My question is, how can I fix this?

Will setting the core.autocrlf to input and cloning again the repo will help? When did these \r get introduced?

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150

1 Answers1

5

What is the correct core.autocrlf setting I should use?

Simple: false.

core.autocrlf applies to all files (including binaries) and can corrupt them on checkout.
Even core.safecrlf is too encompassing.

I prefer using .gitattributes eol directives, where you specify exactly what you need for each file.

Plus:

  • git config is local, and not versioned: you would rely on other developers to make the exact same "correct" configuration;
  • .gitattributes is versioned: other developers will benefit from it automatically;
  • core.autocrlf would override any .gitattributes carefully set directives.

So in your case, in a .gitattributes file:

*.sh         eol=lf

See more examples in "Force LF eol in git repo and working copy".

Note:

have their lines finished in \r

I suspect rather: \r\n not \r (see Newline representation)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250