Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How can I prevent a specific commit from being merged into another branch?

Tags:

git

merge

Our company Git workflow is as following: we have a master branch, some feature/* branches to develop new features that are merged back to master when the job is done, and also release/* branches. These branches are created before a product release and are designed for bug fixes, with no new feature, and those bug fixes are then merged back occasionally into the master branch.

From time to time, it happens that a specific commit in a release/* branch is a change that we don't want to merge back to master: for example when the release number is incremented. Since there are other important fixes in the branch, for sure someone will sooner or later incorporate that said local commit into master, breaking something in the main branch.

The current "solution" I know about is to merge the release/* branch into master immediately after the local commit is done, revert the local commit and then push. It kind of works, but the history is not clean. In addition, this does not prevent the local commit to be merged into another branch than master.

Is there any better way to solve that problem in the described workflow ?

like image 762
prapin Avatar asked Apr 05 '16 21:04

prapin


1 Answers

As far as I know, it is not possible to merge in a commit without also merging in all of its parent commits, which sounds like what you are trying to do.

However, a slight change to your workflow could fix this issue.

Similar to the Git Flow model, you can create a hotfix/* branch to fix the bug, instead of committing directly to the release branch. This branch should probably be based off of master (at the first commit that is a parent of any relevant release branches), and it should be merged into master as well as any release branches it affects.

That way, the release branches need never be merged into master, and can be reserved for release-specific fixes.

like image 115
Scott Weldon Avatar answered Oct 16 '22 13:10

Scott Weldon