Question

Say, I have Repo1 as follows

special ->                      E ... F ... G ... H
                               /
master  ->  A ... B ... C ... D ... X ... Y ... Z

how do I start a Repo2 with master from E? That is for Repo2 I'm not concerned with history before E at all.

Was it helpful?

Solution

If the history that you want to preserve contains merges, the simplest way may be to use a graft to temporarily cut off the unwanted history, then filter-branch to create a branch that has that view of history as the permanent one.

cd /path/to/repo
git checkout -b newbranch special
git rev-parse E > .git/info/grafts
git filter-branch
rm .git/info/grafts

This assumes that you don't currently have any grafts. Since grafts are rarely used and it would probably be a good idea to do this in a fresh clone anyway, that shouldn't be a problem.

OTHER TIPS

git checkout --orphan newbranch E
git commit -c E
git cherry-pick F..H
git init --bare /path/to/new/repo
git push /path/to/new/repo HEAD:master

While git filter-branch could be involved, this article gives an original solution with patches:

Create a bunch of patches, like so:

git checkout find-ls
git format-patch 9758db3 # where find-ls branched

If you need to have your new repo have a different structure, you might need to hack the patches. I just used:

perl -pi -E 's|LEADING-DIR/||g' *.patch

Then you can apply the patches:

mv 0*.patch where/I/want/my/new/repo
cd where/I/want/my/new/repo
git am *.patch

The easy and obvious way: Check out E and make a copy of the working directory, but make sure you don't carry along the .git directory. Now initialize a new git repo from there and move the other commits over. git format-patch and git apply are your friends.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top