0

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
sighol
  • 2,678
  • 6
  • 28
  • 34

2 Answers2

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.

Vampire
  • 35,631
  • 4
  • 76
  • 102
0

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

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • This does not work, since the git repositories doesn't share history. The last commit of A and the first commit of B has the exact same content. But their SHA1 hashes aren't the same. Both repos has been converted from TFS. – sighol Mar 17 '17 at 15:31
  • @sighol What do you mean by "doesn't work"? I used `git merge` as an example. Perhaps `git rebase` is more appropriate for your situation. – Code-Apprentice Mar 17 '17 at 18:12
  • I don't think `git merge` or `git rebase` will work since the two branches have unrelated commits. Branch A: a -> b -> c Branch B: d -> e -> f The two brunches has totally unrelated histories. I want this history a -> b -> c -> d' -> e' -> f' I can't use rebase, since rebase will remove merge commits. – sighol Mar 18 '17 at 06:39
  • 1
    Well, `merge` can be used with unrelated histories using the `--allow-unrelated-histories` switch, but this is not what you actually want in your situation. And `rebase` can be used with any histories if you use the `--onto` switch, but again not really what you want in your situation. And you can also make `rebase` keep merge commits with `--preserve-merges` which *could* produce the result you want, especially if you don't reorder the commits. But again, not what you want in your situation. :-) – Vampire Mar 18 '17 at 13:47