简体   繁体   中英

git branch from branch instead of from master

I have created a adjacent branch from another adjacent branch instead of from master branch. I have added the changes and pushed. Now I have seen that it is like

*   master commit update readme (this is how I have noticed it)
| * adj_br_2 commit blahblah
| * adj_br_1 commit blah
|/
*   master commit blblbl

Now I want to create the 2nd branch from master instead of from 1st branch.

*   master commit update readme (this is how I have noticed it)
| * adj_br_2 commit blahblah
|/
| * adj_br_1 commit blah
|/
*   master commit blblbl

Is there a way to do it without clearing and recreating the branch? In fact I need a fast way to fix it. Any suggestions?

I would just create a new one from the master:

git checkout -b new-branch master

and then if your original branch contained commits you want to take in the new branch, you can cherry-pick them:

git cherry-pick commit1 commit2 ...

and then you can remove the second adjacent branch you wanted to recreate:

git branch -d adj_br_2

In git, creating branches is pretty cheap and fast, you can afford to create new ones whenever you need to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM