Konrad Höffner
Konrad Höffner

Reputation: 12217

Add missing git history

I incorrectly moved a GitHub repository (A) to a new Bitbucket repository (B) by adding all files from A to B, which lost all history. I did some work (multiple commits) on B and realized my error, so that now A contains the old history until a certain point and B contains the new history from that point on. How can I merge the history of A with B so that B contains the full history of the files?

P.S.: I guess the main problem will be that the first commit on B is different from how it would be at a because with no history it contains the full text of each file.

Example

Repository A

Commit 1: Create new File X
Commit 2: File X
+ Hello World
Commit 3: File X
+ This is a test

Repository B

Commit 1: Create new File X:
+ Hello World
+ This is a Test
Commit 2
+ This is a new line

I want to create a new repository C with the following history:

Commit 1: Create new File X
Commit 2: File X
+ Hello World
Commit 3: File X
+ This is a test
Commit 4:
+ This is a new line

Upvotes: 1

Views: 209

Answers (1)

Jan Matejka
Jan Matejka

Reputation: 1968

git init c
cd c
git remote add a ...
git remote add b ...
git branch -u a master
git pull
git checkout b/master -b new-master
git rebase master

Might also help to first drop the initial file addition from the new-master; or it might only make it more difficult, not sure now.

Upvotes: 1

Related Questions