How do I fix line ending issues after migrating from SVN to git?

只愿长相守 提交于 2019-12-13 16:06:49

问题


I just finished converting a Subversion repository to git using

git svn clone--stdlayout --authors-file=ourcommitters.txt svn://svn.internalserver.com

While doing so, I had the git flag 'core.autocrlf' set to 'true' - just in case that matters.

After a long time, the command finished. I cleaned the resulting git repository a bit (deleting unneded branches, creating tags etc.) and now everything looks really nice and works well. The repository is hosted on a Linux box, and cloning that onto other Linux boxes works really well.

However, I noticed one problem: when cloning the repository onto a Windows box, some files appear to be modified when switching branches. For instance, I do this:

git clone svn://our.git.server/foo
git status                           # Everything is clean
git checkout -t origin/maintenance   # Switch to maintenance branch
git status                           # Everything is clean
git checkout master                  # Back to master branch
git status                           # A few files are modified!

When doing a 'git diff', I notice that the modified files seem to differ in nothing but their line endings. When researching this a bit, we noticed that these files had accidentally been checked in using CR-LF line endings (instead of LF line endings) in Subversion, and this bug was converted into our git repository.

Is there any way to fix this issue in our repository (so far it wasn't cloned very often, so some history rewriting would be fine) without doing a 'cleanup commit' or the like? Maybe we can silently rewrite the affected objects somehow?

Alternatively, we could fix this in Subversion - and then issue the 'git svn clone' command above again. This seems to work incrementally (it would just pick up the latest line ending fix commit) but again - it creates a commit. I wonder whether I can get around that.


回答1:


It turned out that the easiest way was to fix the faulty files in Subversion, and then clone again using

git svn clone--stdlayout --authors-file=ourcommitters.txt svn://svn.internalserver.com


来源:https://stackoverflow.com/questions/1577458/how-do-i-fix-line-ending-issues-after-migrating-from-svn-to-git

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