Taylor Austin
Taylor Austin

Reputation: 5987

How to combine two git histories and place the new history on top of the old one?

I have two git branches with completely different histories.

What I need to do:

I need to get branch B's history and combine it and place it ontop of branch A's history. I want to "merge" branch B into branch A but they have completely different histories.

What can I do?

Upvotes: 0

Views: 59

Answers (2)

Philippe
Philippe

Reputation: 31107

I think you should use git rebase (because you will have conflicts hard to solve when applying the first commit) but instead, use the graft feature and the do a git filter-branch.

http://gitolite.com/archived/grafting.html

Upvotes: 3

Kamil
Kamil

Reputation: 2862

It's pretty common that two Git branches have different histories of commits (at least from the moment they branched from parent). You want to get all commits from branch B and "place them ontop of branch A's history", so looks like the most suitable tool will be a git rebase. I can't see any information about merges performed for both branches, but I assume that you wan't to preserve all of them. In such case I'd suggest to try with

git checkout B
git rebase A --preserve-merges

You might get some conflicts during rebase process, so following commands can also be helpful:

git add <some_file_with_conflict>
git rebase --continue

More information about rebasing branches you can find in this Git rebase documentation and this Git Book

Upvotes: 1

Related Questions