Are CRLF lines ok in a Rails project deployed on Linux?

亡梦爱人 提交于 2019-12-18 18:22:14

问题


I have a Git repository (originally CVS, then SVN, now Git) containing a Rails project that has been deployed on Linux for a while now. Everything seems to run fine.

Now that I've converted to git, I see that many of my files in the repository contain CRLF line endings. I'd love for it to all be consistent (LF), but not at the expense of loosing the edit history of every file that has CRLF line endings.

Can you think of any reason I can't leave the files as they are? I seem to remember there being a problem with shell scripts or cron files or something that didn't respond to CRLF very well.

Also, I know all about the Git options core.autocrlf and core.safecrlf, But is there some way to have it convert all text files from CRLF to LF on checkout (for the linux side) ... i.e. a core.autolf option or something similar?


回答1:


If it is ok for you to rewrite your repository's history (see problems with rewriting history) you could use git filter-branch to convert CRLF to LF:

git filter-branch --tree-filter 'find . -path './.git' -prune -o -type f -exec dos2unix \{} \;' HEAD

Note that if you have binary files in your repository you will have to refine the find command to exclude them.




回答2:


A comment to davitenio's answer and Daniel Beardsley's comment; I believe you could use this little program as a wrapper around dos2unix:

#!/bin/sh
for f in $@; do
    if [ $(file -b -n -i -m /dev/null $f | grep -c "text") -gt 0 ]; then
        dos2unix $f
    fi
done

although there is probably still some corner case that will fail.



来源:https://stackoverflow.com/questions/446244/are-crlf-lines-ok-in-a-rails-project-deployed-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!