I'm trying to merge two repos using git read-tree
.
The problem is, the previous commit history of merged files disappeared. I did check file by file obviously.
I followed normal way of doing subtree merging based on this article:
6.7 Git Tools - Subtree Merging
$ git remote add rack_remote git@github.com:schacon/rack.git
$ git fetch rack_remote
$ git checkout -b rack_branch rack_remote/master
$ git read-tree --prefix=rack/ -u rack_branch
My current workspace structure looks like:
project P
- repoA
- repoB
- repoC
(... and many more repos)
And I wanna change the hierarchy of them and to be like:
project P
- repoA <=== have repoB and repoC inside.
I could't see merged files' history on the example above and mines too on git log
result.
(I wanna underline my repos are svn cloned ones still linked to the svn repository. Could this affect read-tree behavior?)
EDIT: I tried with original Github repos and the problem was the same.
The steps you described do not add the merged history as a second parent. From the text in the link it seems like that was their intention. Since you intention is different, you should modify the commands a bit:
$ git remote add rack_remote git@github.com:schacon/rack.git
$ git fetch rack_remote
Now, first initiate a merge. The command uses "ours" strategy, so it does not really change anything yet.
$ git merge -sours --no-commit rack_remote/master
Then modify the content:
$ git read-tree --prefix=rack/ -u rack_remote/master
And finally commit (will spawn editor):
$ git commit
Now it's done: you have the merged files in subdirectory and their history.
This is probably not the only way to create merge commit with arbitrary content but the first one which worked for me. Note also that there is no need to create a local branch mirroring rack_remote/master
, you can use the remote reference.
PS: you will need to use --follow to track the file histories, because the merge renamed them.