Pushing Git Commits to an SVN Repository
Yesterday I found myself in the awkward position in which I needed to push some commits in a git repository to an existing SVN repository. This came about because as soon as my 3D module was finished at University, I copied my code over to a private git repository and started working from there instead. As luck would have it, I ended up running into a few nasty issues and needed to push my extra commits to the original SVN repository.
Since it took me a while to work out how to accomplish this, I thought I'd write a blog post on it. Credit for this method goes to Pete Goodliffe for figuring out how to do it.
The first thing you need to do is to install git svn, if you haven't already. If you're on Windows, then you probably already have it if you've got git (which you'll need too). If you're not sure, simply type git svn
into a command line (or terminal), and if you don't get a 'svn' is not a git command
message, you've got it installed.
Next, you need to use git svn to clone your SVN repository. Even if you've got a clone sitting somewhere already, you should create a fresh one, just in case. This process may take a long time, depending on how many commits you've made to the SVN repository. Use the following command:
git svn clone {svnRepositoryUrl}
Replace {svnRepositoryUrl}
with the URL of your remote SVN repository. Now that you've done that, cd into the created directory.
Next, we need to add the git repository as a new remote. To do this, type something like this:
git remote add -f remote-repo {gitRepoUrl}
Replace {gitRepoUrl}
with the url of your remote git URL. Now we've set everything up, we can replay the remote git repository's commits overtop the commits in the SVN repository:
git rebase --onto remotes/git-svn --root remote-repo/master
Again, this may take a while. Once this command has completed, all you have to do is a quick git svn dcommit
to push the new commits up to the SVN repository.
Alternatively you can push the SVN commits to the remote git repository by entering the following commands instead of the rebase command above:
git pull remote-repo master # Make sure that the local workspace is in sync with the remote git repo
git push remote-repo # Push the SVN commits to the remote git repo
That's about all I wanted to include in this post. If you found this post useful (and even if you didn't!), please leave a comment down below.