Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working locally with Git when main repository is SVN

Tags:

git

svn

git-svn

There is an open source project I want to checkout and contribute to. The main repository is SVN but I want to work in Git. Is this possible?

Most of my searches turns up guides where you move from SVN to Git (or the other way around) and dont look back.

  • If I checkout the project, make a change and push it to the branch I created on Github, how should I notify the original authors?
  • How hard is it to include a contribution made on a Git repos into a SVN repos?
  • Just comparing two revisions (my latest checkout/pull/update and my own local latest commit), generate a patch from it and send it to them; should this be considered a fallback workflow or is the standard approach?

Assume that the original authors have no interest whatsoever in learning anything other than SVN.

[Update] I dont have, nor do I want to have, commit access to the SVN repository. Im looking for workarounds for that.

[Update2] If patches are indeed my only option, are there any additional caveats I should be aware of?

like image 784
Mizipzor Avatar asked Nov 05 '09 10:11

Mizipzor


People also ask

Can I use Git and SVN at the same time?

You can clone a subversion repository to your machine using git svn clone <SVN repo URL> . The code will be available as a git repository. You can do your work there and make local commits as you please. There is a command line option to get a "shallow" checkout rather than the entire repository which is often useful.

How do I access local SVN repository?

You can either store your repositories locally and access them using the file:// protocol or you can place them on a server and access them with the http:// or svn:// protocols. The two server protocols can also be encrypted. You use https:// or svn+ssh:// , or you can use svn:// with SASL.

How do I checkout code from SVN to local repository?

Check out files from Subversion repositoryIn the Get from Version Control dialog, click Add Repository Location and specify the repository URL. Click Check Out. In the dialog that opens, specify the destination directory where the local copy of the repository files will be created, and click OK.


2 Answers

Luckily there's git-svn for exactly this purpose. It enables you to use git locally while also being able to check in to SVN when you wish to do so. It's fairly straightforward and there are lots of information if you search for git-svn here or via Google.

There's a tutorial at http://flavio.castelli.name/howto_use_git_with_svn that you might want to look at first.

Edit: To generate SVN compatible diffs you can use git diff --no-prefix. Note however that this format is not compatible with TortoiseSVN. If compatibility is needed you would have to use some sort of shell script; see example here: http://mojodna.net/2009/02/24/my-work-git-workflow.html

Edit: One potential downside of git-svn is that it does not handle svn externals. You would have to handle those yourself.

Good luck!

like image 59
lemonad Avatar answered Nov 15 '22 16:11

lemonad


Keeping a Git repository in sync with a Subversion repository is really easy:

Clone the Subversion repository (in this simple example I am ignoring branches/tags)

$ git svn clone https://url/to/repo/trunk

Keep up-to-date with the Subversion trunk:

$ git svn rebase

Now, if you had commit access to the Subversion repo, you could push your changes:

$ git commit
$ git svn dcommit

Otherwise, submitting a patch is your only option, if the committers to the Subversion repository have no interest in using Git:

$ git diff 1cc92b96 > my_patch.patch

In this case it's obviously best not to make commits to the branch you are syncing with the Subversion repo.

like image 38
Ben James Avatar answered Nov 15 '22 17:11

Ben James