svn2git - command failed - error: pathspec 'master' did not match any file(s) known to git
Asked Answered
A

3

12

We are trying to migrate from svn to git using svn2git utility (https://github.com/nirvdrum/svn2git). The utility seems to fail every time with below error. If anyone has seen the same error or have any better alternatives, please share.

command
svn2git https://xyz.xyz.com/svn/svnrepo/ --verbose --authors authors.txt

console output

Running command: git svn init --prefix=svn/ --no-metadata --trunk='trunk' --tags
='tags' --branches='branches' https://xyz.xyz.com/svn/svnrepo/  
Running command: git config --local --get user.name  
Running command: git config --local svn.authorsfile authors.txt  
Running command: git svn fetch  
Running command: git branch -l --no-color  
Running command: git branch -r --no-color  
Running command: git config --local --get user.name  
Running command: git config --local --get user.email  
Running command: git checkout -f master  
error: pathspec 'master' did not match any file(s) known to git.  
command failed:  
git checkout -f master  

P.S. My SVN repo URL is correct too, it's just above the trunk. I am trying this on Win7 64-bit machine.

Artefact answered 19/12, 2016 at 20:10 Comment(3)
do you have a master branch in the git repo?Willms
No, I'm trying to clone svn repo which should create and initialize a new git repo locally.Artefact
I couldn't use svn2git but i tried following 2 options and both worked for me. 1) For complete SVN repo migration - atlassian.com/git/tutorials/migrating-overview 2) For selective branches/tags - janosgyerik.com/…Artefact
B
32

Late, but someone might still need this. I managed to track this down to the issue #241. Long story short, Windows doesn't understand single quotes (') around arguments which the script adds to git command. There are probably various ways to fix it, but I just manually hacked the migration.rb file, namely the following snippet:

    cmd += "--trunk=#{trunk} " unless trunk.nil?
    unless tags.nil?
      # Fill default tags here so that they can be filtered later
      tags = ['tags'] if tags.empty?
      # Process default or user-supplied tags
      tags.each do |tag|
        cmd += "--tags=#{tag} "
      end
    end
    unless branches.nil?
      # Fill default branches here so that they can be filtered later
      branches = ['branches'] if branches.empty?
      # Process default or user-supplied branches
      branches.each do |branch|
        cmd += "--branches=#{branch} "
      end

Note there are no quotes around #{trunk}, #{tag} and #{branch} any more. That did the trick.

Beguile answered 18/3, 2018 at 15:41 Comment(2)
For non-Ruby folks on Windows: Here's the path I used: C:\Ruby26-x64\lib\ruby\gems\2.6.0\gems\svn2git-2.4.0\lib\svn2git to find the migration.rb file.Exarchate
I feel like an angel has floated down from the heavens and blessed me on this dayGordie
F
2

There are pleny tools called svn2git, the probably best one is the KDE one from https://github.com/svn-all-fast-export/svn2git. I strongly recommend using that svn2git tool. It is the best I know available out there and it is very flexible in what you can do with its rules files.

The svn2git tool you used is based on git-svn and git-svn is not the right tool for one-time conversions of repositories or repository parts. It is a great tool if you want to use Git as frontend for an existing SVN server, but for one-time conversions you should not use git-svn, but svn2git which is much more suited for this use-case.

If you are not 100% about the history of your repository, svneverever from http://blog.hartwork.org/?p=763 is a great tool to investigate the history of an SVN repository when migrating it to Git.


Even though git-svn (or the wrong svn2git in your case) is easier to start with, here are some further reasons why using the KDE svn2git instead of git-svn is superior, besides its flexibility:

  • the history is rebuilt much better and cleaner by svn2git (if the correct one is used), this is especially the case for more complex histories with branches and merges and so on
  • the tags are real tags and not branches in Git
  • with git-svn the tags contain an extra empty commit which also makes them not part of the branches, so a normal fetch will not get them until you give --tags to the command as by default only tags pointing to fetched branches are fetched also. With the proper svn2git tags are where they belong
  • if you changed layout in SVN you can easily configure this with svn2git, with git-svn you will loose history eventually
  • with svn2git you can also split one SVN repository into multiple Git repositories easily
  • or combine multiple SVN repositories in the same SVN root into one Git repository easily
  • the conversion is a gazillion times faster with the correct svn2git than with git-svn

There are many reasons why git-svn is worse and the KDE svn2git is superior. :-)

Fold answered 19/12, 2016 at 21:36 Comment(8)
Why do you copy-paste the same answer over and over?Queen
@Queen it is not the same answer, but adapted to the question. Actually the questions are quite different, but the answer is most often "use the right tool and it works much better".Fold
i'm not sure whether it will work in your case, but what about voting to close as duplicate of? Select the most popular and relevant question and vote similar questions to be closed as duplicates.Queen
This would not really be correct, as the questions are very different and all are about different problems. It is just the same solution I suggest, with question-specific parts in the answer.Fold
It is actually quite annoying to see duplicate answers like this. Many of us who get here by searching have to sift through the same answers over and over again to find one that actually works.Discrepancy
If the many of you want to do a one-time conversion, the answer is always the same, use the right tool for the job instead of using a butter-knife to do brain surgery. It works, but it is not really appropriate. Following that advice you only need to read one of those answers that are quite similar but not the same. ;-)Fold
@Vampire: You did a good job of selling the KDE svn2git but all the examples I can find are for SVN repos in the file system. Is it possible to use it with a remote repo hosted online?Klina
Yes and no. To run svn2git you after all need the files locally. If you do not have direct access to those files, there are tools that can get you the files like for example rsvndump.Fold
B
0

Not much of an "answer", but here is the solution for my case. BTW, that error message from svn2git was really far from helpful.

My reason for getting exactly the same error was that I didn't use the full path of the trunk when doing the initial import.

The SVN repo had structure like this:

https://example.com/folderA/projectName
 - trunk
 - tags
 - ...

and I ran the svn2git with only svn2git https://example.com/folderA --username ....

When I included also the "/projectName" to the repo path, and did this:

svn2git https://example.com/folderA/projectName --username ...

...all worked great. Also, before retrying - I removed the existing .git folder, from previous attempts.

Bystander answered 18/1, 2019 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.