Xcode不再提供svn,需要用Homebrew安装。安装git和svn后,执行git svn命令出现如下错误信息:
Can't locate SVN/Core.pm in @INC (you may need to install the SVN::Core module) (@INC contains: /usr/local/Cellar/git/2.27.0/share/perl5 /Applications/Xcode.app/Contents/Developer/Library/Perl/5.18/darwin-thread-multi-2level /Library/Developer/CommandLineTools/Library/Perl/5.18/darwin-thread-multi-2level /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.4 /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/Cellar/git/2.27.0/share/perl5/Git/SVN/Utils.pm line 6.
BEGIN failed--compilation aborted at /usr/local/Cellar/git/2.27.0/share/perl5/Git/SVN/Utils.pm line 6.
Compilation failed in require at /usr/local/Cellar/git/2.27.0/share/perl5/Git/SVN.pm line 25.
BEGIN failed--compilation aborted at /usr/local/Cellar/git/2.27.0/share/perl5/Git/SVN.pm line 32.
Compilation failed in require at /usr/local/Cellar/git/2.27.0/libexec/git-core/git-svn line 22.
BEGIN failed--compilation aborted at /usr/local/Cellar/git/2.27.0/libexec/git-core/git-svn line 22.
该错误说明git找不到 CVN::Core 模块(没有安装,或者路径不正确)。用命令“sudo cpan SVN::Core”重新安装CVN::Core模块,如果提示找不到apr等,可以执行命令
sudo bash -c 'PATH=$PATH:/usr/local/opt/apr-util/bin:/usr/local/opt/apr/bin \
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}":/usr/local/opt/apr/libexec/lib cpan SVN::Core'
安装。然后用命令“brew reinstall git”和“brew install subversion”重新安装git和svn,但执行“git svn”命令时仍然出错。
git svn模块是用perl开发的,执行命令“git svn”相当于执行perl脚本“/usr/local/Cellar/git/2.27.0/libexec/git-core/git-svn”。经检查发现该脚本的第一行为“#!/usr/bin/perl”,即指定使用系统自带的“/usr/bin/perl”(5.18版)来执行该脚本。但是,如在命令行执行perl,调用的是5.30版的perl(/usr/local/bin/perl,由Homebrew在安装git时自动安装),因此在用cpan安装CVN::Core 模块时,是用5.30版的perl来编译安装的。因此,这个错误产生的原因是用5.18版的perl执行git-svn脚本,但调用的是由用5.30版的perl编译安装的CVN::Core模块。
这个错误的解决方案是改用5.30版的perl(/usr/local/bin/perl)来执行git-svn脚本,即保证用于执行git-svn脚本和用于编译CVN::Core模块的perl版本一致,都采用/usr/local/bin/perl。具体方法如下:
-
在“~/.profile”文件(对于zsh为“~/.zshrc”)中指定所使用的的perl库PERL5LIB,即增加:export PERL5LIB=/usr/local/opt/subversion/lib/perl5/site_perl/5.30.3/darwin-thread-multi-2level/:$PERL5LIB
-
显式指定执行git-svn脚本的perl,即用命令/usr/local/bin/perl /usr/local/Cellar/git/2.27.0/libexec/git-core/git-svn
-
或者把脚本/usr/local/Cellar/git/2.27.0/libexec/git-core/git-svn的第一行由原来的“#!/usr/bin/perl”改为“#!/usr/local/bin/perl”,直接执行git svn。
如果SourceTree使用了自带的git,可以将/Applications/Sourcetree.app/Contents/Resources/git_local/libexec/git-core/git-svn的第一行由原来的“#!/usr/bin/perl”改为“#!/usr/local/bin/perl”。