Moving history between git repos

7:28 pm General

So GLib and GTK+ have officially moved from svn to git this week. I had been doing some work in my own git repos, but they were based on various git-svn checkouts and they were all hashed differently, so it wasn’t possible to just merge from one of them into the new official git repos.

It turns out that it’s quite easy to merge your history over, though. Here’s what I did.

Say there is an old git repo with a branch called new-awesome-stuff. You want to create a branch in the new git repo with the same name, and merge the history over.

(in the old repo)

git checkout new-awesome-stuff
git format-patch master

This generates patches for each revision.. say there were 34 revisions in this branch. You’ll get 34 patch files whose names begin with 00nn (where nn is 01..34).

(in the new repo)

git checkout -b new-awesome-stuff
git am 00*.patch

If you’re putting things on github as I am, this should help you maintain your work in a single repo instead of having four different repos for the same project as I had. 🙂

One Response

  1. alexl Says:

    You don’t need to do that.
    Just fetch the other repo into your git repo, create a local branch foo based on a branch from that, then:
    git rebase –onto master foo

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.