Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: svn is not a git command - Mac

Tags:

git

git-svn

I had no issues yesterday but today I cannot run git svn anymore. It says:

git: 'svn' is not a git command. See 'git --help'.

The most similar commands are
    fsck
    mv
    show

I don't know if it's relevant but since yesterday I updated npm(6.14.4) and node (v12.6.0).

I'm on macOs Catalina

like image 316
Greg Avatar asked Mar 26 '20 14:03

Greg


People also ask

What is Git SVN command?

Git SVN is a feature in Git that allows changes to move between a Subversion and a Git repository. Git SVN is a good feature to use if you need to allow changes to go between Git and SVN repositories.

What is Git command on Mac?

Git is a version control system that allows developers to track a project and actively contribute without interfering in each other's work. It supports collaboration within a project and helps prevent miscommunication or code clashing between team members.

Can you use SVN with Git?

The git-svn tool is an interface between a local Git repository and a remote SVN repository. Git-svn lets developers write code and create commits locally with Git, then push them up to a central SVN repository with svn commit-style behavior.


3 Answers

  1. First install git and svn with brew
brew install git
brew install svn
  1. Use system default perl at /usr/bin/perl

if you installed perl with brew, please uninstall it.

brew uninstall perl

use which perl to check if using the system default perl at /usr/bin/perl. Make sure the git-svn use the #!/usr/bin/perl use following command to check which perl is git-svn using

$ head -1 $(brew --prefix)/opt/git/libexec/git-core/git-svn
#!/usr/bin/perl
  1. check you svn's perl version at /usr/local/Cellar/subversion/1.14.1/lib/perl5/site_perl/5.18.4

  2. If you got error Can't locate SVN/Core.pm in @INC you also need to set PERL5LIB path, for Catalina:

export PERL5LIB=/usr/local/lib/perl5/site_perl/5.18.4/darwin-thread-multi-2level

for Big Sur:

export PERL5LIB=/usr/local/lib/perl5/site_perl/5.28.2/darwin-thread-multi-2level

Reference: https://github.com/Homebrew/homebrew-core/issues/52490

like image 153
situee Avatar answered Oct 22 '22 23:10

situee


I found a simple fixed solution for macOS Big Sur v11.1 (20C69) on GitHub.

  1. make sure install git, svn, perl with brew.

    brew install git
    brew install perl
    brew install subversion
    
  2. edit /usr/local/Cellar/git/2.30.0/libexec/git-core/git-svn.

    replace #!/usr/bin/perl with #!/usr/local/bin/perl

  3. git svn works.


The above solution only works under perl 5.32.0.

When I updated the perl to 5.32.1, git svn can no longer work.

Can't locate SVN/Core.pm in @INC (you may need to install the SVN::Core module)...

I found a solution on GitHub.

Now subversion built with system perl, so we can add an environment variable to solve this problem:

export PERL5LIB=/usr/local/lib/perl5/site_perl/#{perl_version}/darwin-thread-multi-2level

You should replace #{perl_version} with system perl's version.

For macOS Big Sur:

export PERL5LIB=/usr/local/lib/perl5/site_perl/5.28.2/darwin-thread-multi-2level
like image 28
jqgsninimo Avatar answered Oct 22 '22 23:10

jqgsninimo


UPDATE: SEPTEMBER 2020

It seems the end is here. Following the original suggestion will delete subversion forever. I found a verified version of Subversion for MacOS and downloaded and installed it. I then needed to add Subversion to the $PATH variable to supersede Apple's svn (which just prints a message saying subversion is no longer included). To add it, add this line to your ~/.zprofile:

export PATH=/opt/subversion/bin:$PATH

This will fix svn. I still have not figured out how to fix git svn.

NB: I also am aware that one can get subversion from homebrew, but homebrew is prohibited by my company's policies. If homebrew works better for somebody, please post your results here.

ORIGINAL ANSWER: MARCH 2020

Same thing happened to me today. After software update, git svn and svn are gone. It seems that Apple is deprecating Subversion in XCode:

Command line tool support for Subversion — including svn, git-svn, and related commands — is no longer provided by Xcode. If you need Subversion or related command line tools, install the Command Line Tools package by running xcode-select --install. (50266910)

In the mean time, I was able to resolve this situation by deleting the XCode command line tools and reinstalling them:

sudo rm -Rf /Library/Developer/CommandLineTools
sudo xcode-select --install

After that, git svn and svn were back. Hopefully that will give us a stay of execution before final deprecation and deletion.

like image 6
deepdivedylan Avatar answered Oct 23 '22 01:10

deepdivedylan