How to append a git repository on top of another

感情迁移 提交于 2019-12-08 12:48:02

问题


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:

  1. 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.

  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!