My favorites | Sign in
Google
             
Search
for
Updated Jul 22, 2008 by azmatalipasha
ImportingFromGit  
Import a Git repository to Google Code.

Introduction

You can have Google Code act as a stable read-only Subversion mirror of a Git project. In this model, patches are first applied to the central Git repository and exported to Google Code later.

Instead of merely providing a link to your repository, why not widen your audience with just a handful of commands? Open up your Git-hosted project to all Subversion users, whose patches can be integrated via Git.

We presume some familiarity with Git, though blindly typing the commands below should produce acceptable results.

1. Create Subversion-aware Git clone

Naturally, your official source tree lives on some Git-capable server, which we denote by $GIT_REPO. http://code.google.com/hosting/createProject creating a new Google Code project, initialize an intermediary repository and fetch the Git tree:

 $ git svn clone --username you https://your-project.googlecode.com/svn/trunk
 $ cd trunk
 $ git fetch $GIT_REPO

The Subversion repository must be nonempty. A new Google Code project contains one revision by default, but if you reset it, you should also create a first revision.

Create a temporary branch for the fetched repository, and tag its head:

 $ git branch tmp $(cut -b-40 .git/FETCH_HEAD)
 $ git tag -a -m "Last fetch" last tmp

2. Apply initial commit

Unfortunately, Git treats the initial commit specially, and in particular, cannot rebase it. Work around this as follows:

 $ INIT_COMMIT=$(git log tmp --pretty=format:%H | tail -1)
 $ git checkout $INIT_COMMIT .
 $ git commit -C $INIT_COMMIT

3. Rebase and submit

Apply all the other commits to the temporary branch, and make it the new master branch:

 $ git rebase master tmp
 $ git branch -M tmp master

Lastly, commit the changes to Google Code:

 $ git svn dcommit

To more faithfully represent deleted subdirectories and copies of unmodified files, run dcommit with the options \--rmdir and \--find-copies-harder. Be aware the latter option can be expensive.

4. Update Google Code

Later, export Git repository updates to Google Code as follows:

 $ git fetch $GIT_REPO
 $ git branch tmp $(cut -b-40 .git/FETCH_HEAD)
 $ git tag -a -m "Last fetch" newlast tmp
 $ git rebase --onto master last tmp
 $ git branch -M tmp master
 $ git svn dcommit
 $ mv .git/refs/tags/newlast .git/refs/tags/last

For simplicity, we've exported directly to Google Code. It may be faster to first export to a local Subversion repository, and then mirror it to Google Code via svnsync.

The content on this page created by Google is licensed under the Creative Commons Attribution 3.0 License. User-generated content is not included in this license.


Comment by davetron5000, Sep 17, 2008

If a git-svn dcommit fails:

  1. open .git/logs/HEAD
  2. Find the hash of the commit that's the head of your git repo. Hopefully you remember the commit message and can figure it out, but it should be pretty obvious
  3. git reset --hard _hash from log_ (This gets your working dir back to where it was before you did a git-svn dcommit).
  4. git-svn rebase
  5. git-svn dcommit

Repeat these steps until the commit completes normally. If the dcommit fails with some error, it will pick up where it left off.

Comment by tguyot, Jan 30, 2009

I have a different way to do it. Was meant to keep an existing SVN repository updated but most of your setup instruction can be used as well.

http://repo.or.cz/w/nagiosplugins.git?a=blob;f=tools/git2svn.pl

It uses "git svn set-tree", but I believe the result is pretty much the same. The --add-author-from option in set-tree makes it possible to know who committed the code (I'm not sure if it can be done with your method).

Comment by Dan.Kel...@Dal.Ca, Jun 27, 2009

Does anyone have an idea when google will support git in a direct way? I am perhaps in a large group of developers who have switched to git. I like the issue-tracking on googlecode, but it is starting to become tiresome, typing svn commands when my fingers now "know" git comments better. (git-svn is not much help; it's just a third set of commands for my fingers to type, and my goal is to reduce by one, not increase by one!)

Comment by d.borkm...@gmail.com, Sep 20, 2009

git on googlecode would be awesome! c'mon fellas, why not (directly) supporting it?

Comment by stephane.maniaci, Nov 22, 2009

Am I the only one unable to make the --rmdir flag work successfully ? I've been doing many git svn dcommit --rmdir but it still doesn't work. :(


Sign in to add a comment