sighol
sighol

Reputation: 2828

How to append a git repository on top of another

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

Upvotes: 0

Views: 889

Answers (2)

Code-Apprentice
Code-Apprentice

Reputation: 83577

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

Upvotes: 0

Vampire
Vampire

Reputation: 38734

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.

Upvotes: 1

Related Questions