Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bringing selective changes from develop to master

Tags:

git

git-flow

I'm using git-flow to maintain my branches, hence I have a master and develop branches.

Develop is several commits (~50-100) ahead of master.

However, there is a need to bring selective features from develop to master ahead of schedule.

How can I do this? Should be using cherry-pick? What happens if I rebase develop on master again later before the final merge back to master?

like image 803
Nora Olsen Avatar asked Jul 29 '13 08:07

Nora Olsen


People also ask

How do you change changes from one branch to the master?

First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch. Note: git merge merges the specified branch into the currently active branch.

Why should you not push to master?

Not committing to master prevents colliding commits and having to merge each time 2 people change the same file.

How do I pull changes from master to branch in Sourcetree?

Under Branches, double-click the feature branch that is behind to switch to that branch. Click the Merge button. From the popup that appears, select the commit you want to merge into your feature branch. Check the Create a commit even if merge resolved via fast-forward option at the bottom.


2 Answers

Have you considered creating another develop branch just for integrating these particular features, then using either rebase -i to remove commits you don't want, or cherry-pick the commits you do want into that branch?

It seems that you might even be able to use a git flow release branch to do this, though if you do you'd have to go with the interactive rebase/removal approach. It's not the way release is intended, but it at least keeps master clean.

The process of removing changes at release time is documented pretty well in http://dymitruk.com/blog/2012/02/05/branch-per-feature/ specifically in the section titled "Taking features out is more powerful than putting them in". You may have difficulty if your features didn't start from the same commit (which, if you follow git-flow, they probably aren't). But you can try to make the best of it.

Example: interactive rebase

$ git checkout -b reduced_functionality_branch develop
$ git rebase -i sha1-for-previous-release-point
...remove the stuff you don't want...

At this point, reduced_functionality_branch should contain only the commits you want to be released.

like image 183
Chris Cleeland Avatar answered Sep 18 '22 07:09

Chris Cleeland


You can use "git cherry-pick"

Please note that since you bring selective commits, commits must on source branch must be complete. You may get some merge conflicts as well.

like image 27
forvaidya Avatar answered Sep 18 '22 07:09

forvaidya