Search code examples
ruby-on-railsrubygitnewlinecore.autocrlf

Ruby on Rails, Git and CRLF - nontrivial


I am learning Ruby on Rails and I use Windows 7. When I try to commit my changes to Git, I receive the fatal: LF would be replaced by CRLF message.

It seems that rails generate generates files with LF, not CRLF. Of course, I may switch from

git config --global core.autocrlf true
git config --global core.safecrlf true

to

git config --global core.autocrlf true
git config --global core.safecrlf warn

but I don't like the possibility of crushing any committed binary into pieces.

I tried to avoid the problem with .gitattributes, but my lines like

* text=auto
*.rb text

do not help.

Is there a way to make Rails generate files with CRLF ending? Or is there a way to make Git auto-transform the .rb and .erb files, but not others?


Solution

  • I don't like the possibility of crushing any committed binary into pieces.

    Are you sure that's a real problem?

    If you turn the warnings off (core.autocrlf true) git will make the adjustments when you commit and you can continue being productive.

    If you truly have a solid reason for not wanting to do this you are going to have difficulty as I don't think there is a simple way (there is always some way) to have Rails generate files with the CRLF ending and it's weird to have git auto-transform based on file type.

    I can certainly be wrong, but it seems like you're trying a bit too much to work against your tools?

    Possibly useful reference: git commit creates assets and temporary files for some reason

    If you really want to go down the road of attempting to configure git to make these changes you can check out a git attribute filter driver as suggested in this response: Can git automatically switch between spaces and tabs?

    Another useful reference to the above proposed solution: https://stackoverflow.com/a/2354278/1026898