问题
Consider that you have a repository https://gitlab.com/my_repo with at least two branches Master and Develop. You have forked the repo into a private one https://gitlab.com/my_repo_fork. You have applied some edits to the Master branch. Now you want to turn the local Master into a new branch of the original repo, branched from the Develop branch. So What I have
https://gitlab.com/my_repoMasterDevelop
https://gitlab.com/my_repo_forkMaster* (edited)Develop
and what I want to have:
https://gitlab.com/my_repoMasterDevelop-
|-> Improvment/number(from the editedMaster*)
I would appreciate it if you could help me know what is the safest way to do this. Thanks for your support in advance.
回答1:
I would create a branch from master, commit the changes and rebase the branch onto the develop branch and then solve merge conflicts:
On master
git checkout -b Improvement/number // create the new branch and add changes
git add .
git commit -m "<message>
git rebase Develop // rebase the new branch onto Develop
Initially, the new branch contains the changes from master:
https://gitlab.com/my_repo_fork
Master (now clean)
|-> Improvment/number
Develop
The rebase removes ("cuts") the branch from master and applies the changes to Develop:
Master (now clean)
Develop
|-> Improvment/number
For a description with better graphics see https://git-scm.com/book/en/v2/Git-Branching-Rebasing
来源:https://stackoverflow.com/questions/60771382/turning-a-fork-to-a-new-branch-of-an-existing-branch