> From: Richard Kennaway <richard.kenna...@gmail.com>
> This is an obviously insane arrangement, but never mind how it got like 
> that, it is like that. I would like move from the current state, which is a 
> directory Z containing repositories A, B, C, D, to having a git repository 
> Z, containing directories A, B, C, D.
> If I didn't care about preserving history or any but master branches I 
> could just export everything from all the repositories and create a brand 
> new repository. But I do want to preserve history and branches.

One approach that should be workable runs like this.  Unfortunately, I
don't know Git well enough to know exactly the right commands, but if
it does what you want, you can work out how to do it, and probably
write a script that does it fairly automatically.

1. Create a new, empty repository.

2. For each branch that you want to merge:  (That is, you want to combine
branch A.b1 of A, branch B.b1 of B, branch C.b1 of C, etc., into
branch b1 of the new repository.)

3. Import each of the branches into the new repository using
git-fetch.  Give each one a unique branch name in some manner.  This
gets all the needed objects for the new branch into the new
repository's object store.

4. Delete all the files in the working directories of the new
repository and manually assemble the file tree that you want in the
working directories.  If all you want is one directory containing
subdirectories that contain copies of each component branch, this can
be done by script, copying the file trees from the old repositories.
Use git-add to force the index to match the working directories.

5. Use git-write-tree to create a tree object from the index.

6. Use git-commit-tree to create a new commit, giving it the hash of
the tree created in step 5 as the tree pointer, and using multiple -p
arguments to list as parents the hashes of all of the source branches.

7. Use git-update-ref to update the corresponding branch head in the
new repository with the commit created in step 6.

The result is a branch in the new repository whose head commit has the
contents you want, and which lists as parents all of the component
branches you combined to create it.  Presumably the Git commands which
try to track the origins of each file can find which of the parents
each file came from.


You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to