简体   繁体   中英

Rebasing branch that was created from a feature branch

I was working on a feature branch that I pushed to origin. Then I created another feature branch but I didn't checkout master before creating it. Now my second feature branch has the commits from the first feature branch which aren't yet merged to master.

I tried to rebase it and update the rebase to origin - unsuccesfully:

git checkout second-feature-branch
git rebase master
git push origin second-feature-branch --force

I already committed to the second branch.

What I have:

A -- B -- master
                \ 
                 \
                  first feature branch
                                      \
                                       second feature branch

What I want

                  second feature branch
                 /
                /
A -- B -- master 
                \ 
                 \
                  first feature branch

How do I keep only the newest commit on the new feature branch and rebase it to master?

What has happened is you created the second feature branch from the first feature branch. So the second feature branch used the first feature branch as a base.

To fix it, you can create a new branch after checkout to master and then cherry-pick the commits of the second feature branch into the new branch. Then you will get the branches as you need it

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