How to rebase one repo to another

后端 未结 4 1350
眼角桃花
眼角桃花 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:38

    You can add the other repo to your current repo first as a remote and then do a rebase --onto to rebase a range of commits from one repo to a point of common commit in the first repo.

    git remote add project2 <...>
    git checkout project2-master
    git rebase -s recursive -X theirs --onto \
        project1-first-commit project2- start-commit project2-end-commit
    

    Roughly like that. Not that I also specify merge strategy to use the commits from project2 if there are conflicts. You may want to use something else. But here we assume that project2 is "correct" code and project1 is just a remote master.

提交回复
热议问题