简体   繁体   中英

Rebase from another branch and then merge into master after merged the other branch

I'm in this scenario:

  • I have a master with a production version
  • I worked on a new feature from master, without graphics (call it feature )
  • In the same time, my team worked on a new branch from master for a new graphics features (call it graphics ), where I worked too (keeping in standby the other branch)
  • Now, the graphics is almost at the end and I come back to work into branch feature

The branch graphics will be merged into master after finished and reviewed, but now I want to integrate the graphics changes also into my branch feature that also will be merged with master after finished.

So we'll have to merge the feature into master, after graphics had been already merged.

What is the best way to do this? Could I rebase feature with graphics changes? Or merge graphics into feature (in this way will I have the merge graphics twice? )? Or must I cherry-pick all commits?

I hope is clear my scenario!

First, merge graphics into master . Then, rebase feature on top of master .

git checkout master
git merge graphics
git checkout feature
git rebase master

This way, you will acquire the graphics changes and still keep an uncluttered history in feature .

It is highly inadvisable to merge graphics into feature before merging it into master unless you have a particular reason for that.

But if you do have a particular reason, then just go ahead and do it...

git checkout feature
git merge graphics    

Note that depending on circumstances you may want to do a git rebase graphics instead of git merge graphics . The end result (the content of your files on feature ) will be exactly the same, but the history aka the commit tree will look different. The latter will avoid any kind of extra conflicts when you finally merge both branches into master and will look very clean; I would likely prefer that. But hard to tell without knowing what you want to achieve.

NB if you do a git rebase , and later commit more onto graphics , then you need to do the git rebase again before the final merge into master (I suggest doing that immediately after you merged graphics into master ).

Scenario 1, When the graphics is merged into the master ; In this case you can rebase your feature branch from the master as the graphics branch changes are there in master .

Scenario 2, When the graphics branch isn't merged yet and you need the changes; In this case there are two possibility, i. Merge the graphics branch into your feature branch by just taking the graphics branch pull in the feature branch, say you in feature branch then git pull origin graphics .

ii. Do rebase your feature branch against the graphics branch, say you are feature branch the do git rebase feature and git rebase --continue unless all rebase conflicts and merge conflicts resolved.

The best is to rebase your branch with the graphics branch and then let the graphics branch be merged to master and then create a pull request agains the master. This would be great to do.

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