How to rebase one repo to another

后端 未结 4 1349
眼角桃花
眼角桃花 2021-02-05 20:58

Let\'s say I have two different repositories like so:

Project 1:
Init---A---B---C---HEAD1

Project 2:
Init---D---E---F---G---HEAD2

Is there a w

4条回答
  •  时光说笑
    2021-02-05 21:19

    You could treat one as a remote repository to the other. In Project1, run these commands:

    git remote add project2 
    git fetch project2
    git branch --track project2Branch project2/master
    git checkout project2Branch
    

    Use git log to find the hash for the initial commit of that branch (which is Project2). Then run

    git checkout master # or whatever branch you want to rebase
    git rebase 
    

    You've now rebased Project1 with Project2. Since this sounds like a one time operation, where you'll then only be using the one repository, you can cleanup with

    git remote rm project2
    

    So now your master branch is rebased with the init of Project2, and project2Branch has the rest of the history of Project2. It's sort of a hack, but it will do what you want.

提交回复
热议问题