问题
I am in the process of converting a project from TFS to git, and I want to keep all history.
The problem is that the TFS project was moved in TFS one year ago. Using git-tfs I can convert both locations to git, but now I have two git repositories: A and B.
I have managed to get both A and B into the same repository as different branches. Would it be possible to change the parent of first commit in B to the last commit in A?
Branch A: a -> b -> c
Branch B: d -> e -> f
I want to have
a -> b -> c -> d' -> e' -> f'
Solution:
git filter-branch --parent-filter 'sed "s/^\$/-p <last-commit-in-A>/"' HEAD_OF_B
回答1:
Sure, set a graft
, that does exactly that. If you are satisfied with the result you can do a filter-branch
to make this permanently. Or you can use filter-branch
right away with a --parent-filter
.
回答2:
I can think of two solutions:
Create a parent repository and add repositories A and B as submodules. You can learn more about this by reading the documentation for
git submodule
.Add repository B as a remote to repository A:
$ git remote add repoB <directory where repo B is located>
Now you can fetch, pull, merge, and rebase from repo B, for example:
$ git checkout master $ git pull repoB master
(If it makes more sense, you can do this the other way around: add repo A as a remote to repo B. The same concepts apply.)
来源:https://stackoverflow.com/questions/42860987/how-to-append-a-git-repository-on-top-of-another