Is there a way to merge the commit history from an SVN repository to a Git branch?
We currently have several small semi-related SVN repos that are inactive as far as commits go. However, they occasionally need to be used and/or their commit history needs to be reviewed. We would like to move all of them into a single pre-existing Git repo as most of our work is done on Git these days…
In doing research, what I think I want to achieve is to have a Git subtree branch for each SVN repo which has all of the commit history. But, git-svn seems to only allow me to relate 1 SVN repo to 1 Git repo, so I would have to create a git repo for each project first, and then convert to a subtree in the final repo. (I think)
- Migrate huge SVN repo with common trunk to Git
- How to rename a remote branch in Git so that to have a proper history tree
- How to verify svn to git conversion?
- Migrate to GIT from TFS with multiple branches and their history
- Migrating from Mercurial to Subversion
- How to import svn branch to git with trunk history
Is there a way to merge the history from an SVN repo directly onto a branch in my Git repository so that I can effectively skip the step of creating redundant Git repos?
2 Solutions collect form web for “Is there a way to merge the commit history from an SVN repository to a Git branch?”
Everything is easier in git. I’d use a tool like
git2svn to import the Subversion repositories into git.
Once in git, you can setup a new repository with branches. You could set up each branch to track one converted Subversion repository. Once you’ve fetched the change sets, you can clear the remote tracking with
git remote remove. That leaves you with a repository with the various changesets from Subversion on branches.
So, the reason I was wanting to avoid extra repositories was that we are using GitHub to store our repositories and the extra repositories I would need to create would put us over the limit of our current plan.
As such, the trick, I found out, is to keep all of the repositories local. I knew this was a possibility, but wasn’t sure how to reference the local repositories. It turns out it couldn’t have been more easy! Here are the steps I went through:
For each SVN repository:
git svn clone http://svnhost.com/path/to/svn/repo
This will create a local Git repo with all of the history from SVN (even timestamps are preserved!!). Next, go to the repo you want to merge it in to. Create a branch, and pull in the code from:
git checkout -b newsvnbranch1 git pull path_to_newsvnbranch1_git_repo
Now, the remaining steps aren’t part of the original question, but they were the end goal that I needed to accomplish – all the SVN repos and histories merged together, but in their own directories.
git mv trunk newname1 git checkout master git merge newsvnbranch1
Completing those steps for each SVN repo essentially leaves your original Git repo with the following structure:
original |-newname1 (containing the contents of the first SVN repo) |-newname2 (containing the contents of the second SVN repo) |-newname3 (and so on...)
git log will now show the history of each repo intertwined.