3

I use multiple environments thanks to virtual machines, and my code directory is shared between them. I also like my code to have the native (host) line endings.

When I'm on a Windows host, I checkout my code and line endings are converted to \r\n (and it's OK for me). But when I want to execute a shell script from my Linux virtual machine, I get errors telling me the /bin/sh^M doesn't exist.

Can I tell Git to keep Unix endings for this specific file? Is there a better way to deal with line endings on multiple environments?

2 Answers 2

1

For a single file, create a .gitattributes file containing:

*.sh    eol=lf

(Another possible setting is -text, which simply disables line ending conversion.)

1
  • 1
    -text will do other things too that you don't want, like stop showing diffs for the file. Jan 29, 2011 at 19:48
0

You can run dos2unix on the files to format them properly for linux/unix.

1
  • It would make the file look completely different to the VCS. Jan 29, 2011 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .