How to combine two separate unrelated Git repositories into one with single history timeline

后端 未结 2 621
南方客
南方客 2020-12-09 11:24

I have two unrelated (not sharing any ancestor check in) Git repositories, one is a super repository which consists a number of smaller projects (Lets call it repository A).

相关标签:
2条回答
  • 2020-12-09 11:56

    I think you do it like this:

    1. git remote add [repo b]
    2. git fetch//get the repo b into repo a
    3. due to you want to keep the history like this: A0-A1-B1-B0-D1-C0-D0-E0-F0-G0-E1-H(from repo B)-HEAD (new repo A) you can first select the A0 as a start point, after that, use git cherry-pick one by one.

    Hope this is useful for you.

    Br, Tim

    0 讨论(0)
  • 2020-12-09 11:57

    I did something similar (merge history from B into A) like this:

    1. go to your repo A
    2. git fetch <ref to your repo B> master:new-branch-on-A (so, you have copied master branch of B into a new branch 'new-branch-on-A' into your repo A.
    3. git checkout new-branch-on-A
    4. git rebase master (you rebase the new-branch-on-A with the master branch)
    5. resolve conflicts if there are any
    6. git checkout master
    7. git merge new-branch-on-A
    8. git branch -d new-branch-on-A
    9. Done :), your histories are merged. I think all commits from A are before commit from B in the new history (git rebase -i is your friend if needed).
    0 讨论(0)
提交回复
热议问题