问题
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