[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Alioth - Convert SVN repo to Git

On Thu, Mar 26, 2009 at 07:31:59AM +0100, sean finney wrote:
> hi mike,
> On Wed, Mar 25, 2009 at 03:29:59PM +0100, Mike Hommey wrote:
> > You don't need to do that on initial import. You can use a grafts file
> > to create the history you like from these 2 unrelated branches, and
> > you can then use git filter-branch to rewrite the master branch to
> > have the commits rewritten to use this grafted history (then you can
> > remove the grafts file).
> do you think you could post an example of how to do that?  i keep hearing
> about using grafts+filter-branch for such purposes but haven't been able
> to decipher exactly what it entails.

The grafts file format is pretty simple:
sha1-of-the-commit-to-graft( sha1-of-its-grafted-parent)+

This means you can create grafted merges if you put more than one

You can take a look at the grafted history with most of the git tools:
git log, gitk and others follow them.

Once you have set your grafts file, you only need to run git
filter-branch $branch, without more options, and it will rewrite the
commits replacing their parents with the grafted ones.

A small example follows:
$ git init
$ echo a > a ; git add a ; git commit -m a
$ echo b > b ; git add b ; git commit -m b
$ echo c > c ; git add c ; git commit -m c
$ git co -b foo master^^
$ echo d > d ; git add d ; git commit -m d
$ echo c > c ; git add c ; git commit -m c

Now, take a look at the commit graph with gitk --all

Let's say this last commit should be a merge with master, but the
resulting tree still the same. Obviously, since you're on the tip
of the branches, you could just do the following to achieve that:
$ git reset --hard HEAD^
$ git merge master
$ git rm b
$ git commit --amend

But it's still somehow harder than rewriting the history with grafts:
$ echo $(git rev-parse foo) $(git rev-parse foo^) $(git rev-parse master) > .git/info/grafts
$ git filter-branch foo
$ rm .git/info/grafts


Reply to: