I have an existing SVN repo and I would like to import a part of it, with history into an existing Git repo. Could anyone give me a high-level overview of the commands needed to do this?
Summary:
I have a feeling this involves something with git filter-branch
and some strange merges. Any help would be appreciated.
Git installation comes with “git svn”. This will allow you to clone a SVN repository and provide a git interface over it. You can clone from a SVN repo using the git svn clone command.
The high-level workflow for migrating from SVN to Git is as follows: Prepare a migration environment. Convert the source SVN repository to a local Git repository. (Optional) Synchronize the local Git repository with any changes from SVN repository while developers continue using SVN.
# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...
Import into a new repoSelect Repos, Files. From the repo drop-down, select Import repository. If the source repo is publicly available, just enter the clone URL of the source repository and a name for your new Git repository.
It turns out to be pretty complicated, but here's what I did.
Prepare the SVN repository first. I was going to delete the files from SVN afterward, so it helped to put all the files in one directory (this also makes filter-branch
easier later.)
Checked out the SVN repo using git: git svn clone http://path/to/svnrepo
. This creates a git version of the svn repo.
Using the ideas from this SO post, Detach (move) subdirectory into separate Git repository, I used the filter-branch --subdirectory-filter
to filter the directory that I wanted, and to remove history of other stuff from SVN that I did not want to keep in git. You can also use git subtree
, a new feature, as in Howto extract a git subdirectory and make a submodule out of it?
Then, using the ideas from this SO post, How do you merge two Git repositories?, I imported the new git repo into the parent project that I wanted to add it to. The accepted answer is incorrect, check out the other answers on that page; you want to do a git remote add git-proj <path>
followed by a git pull
.
Finally, push the changes to the git project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With