1. First Blood
之前在Windows环境下进行svn到git的迁移是很简单的,参考官方文档。
可是在macOS环境下(macOS High Sierra 10.13.2),输入:
$ git svn
神奇的事情发生了,报了以下错误:
can't locate SVN/Core.pm in @INC (you may need to install the SVN::Core module) (@INC contains: /usr/local/git/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level /usr/local/git/lib/perl5/site_perl/5.18.2 /usr/local/git/lib/perl5/site_perl /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /usr/local/git/lib/perl5/site_perl/Git/SVN/Utils.pm line 6.
BEGIN failed--compilation aborted at /usr/local/git/lib/perl5/site_perl/Git/SVN/Utils.pm line 6.
Compilation failed in require at /usr/local/git/lib/perl5/site_perl/Git/SVN.pm line 25.
BEGIN failed--compilation aborted at /usr/local/git/lib/perl5/site_perl/Git/SVN.pm line 32.
Compilation failed in require at /usr/local/git/libexec/git-core/git-svn line 21.
BEGIN failed--compilation aborted at /usr/local/git/libexec/git-core/git-svn line 21.
看错误内容初步分析应该是svn安装问题,macOS是自带svn的,猜测svn损坏需要重新安装,Google之后找到重装方式:
- 安装 Command Line Tools
$ xcode-select --install
选择安装 等5-6分钟就好了
- 创建软链接
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Library/Perl/5.18/darwin-thread-multi-2level/SVN /System/Library/Perl/Extras/5.18/SVN
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Library/Perl/5.18/darwin-thread-multi-2level/auto/SVN/ /System/Library/Perl/Extras/5.18/auto/SVN
2. Double Kill
ln: /System/Library/Perl/Extras/5.18/SVN: Operation not permitted
再次Google之后,了解到,由于El Capitan 系统保护机制,上述操作无效了。But,虽然不能写入 /System, 但是可以写入 /Library。
修改路径:
$ sudo mkdir /Library/Perl/5.18/auto
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Library/Perl/5.18/darwin-thread-multi-2level/SVN /Library/Perl/5.18/darwin-thread-multi-2level
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Library/Perl/5.18/darwin-thread-multi-2level/auto/SVN /Library/Perl/5.18/auto/
3. Triple Kill
再次输入git svn
验证,结果还是报错。重新分析,git的常规命令,像更新、提交等都可以正常使用,唯独git svn
执行会报错,会不会是git中某个组件有问题,Google之后查到可以单独安装:
$ brew install git svn
结果再再次报错,提示xcode版本过低,要我升级Xcode。之前有段时间没做Xcode为了清理空间把Xcode删掉了,重新下载5.5G,瞬间蛋疼了。
Updating Homebrew...
Error: Your Xcode (8.3.2) is too outdated.
Please update to Xcode 9.2 (or delete it).
Xcode can be updated from the App Store.
一边下载过程中一边继续Google看有没有别的解决方法,终于在踏破铁鞋无觅处之后,找到了最终解决办法。
4. 终极方法
- 打开用户协议,最后选择agree。
$ sudo xcodebuild -license
- 安装 Command Line Tools
$ xcode-select --install
- 使用cpan安装 SVN::Core包
cpan是下载、安装、更新及管理的Perl工具
$ sudo cpan SVN::Core
- 添加环境变量
#vim ~/.profile:
export PATH=/Library/Developer/CommandLineTools/usr/bin:$PATH
- 重装git,svn
$ brew reinstall git
$ brew reinstall subversion
再次输入git svn
验证,问题解决。
参考资料:
[1] Git-scm:
https://git-scm.com
网友评论