Git: How can I prevent a particular commit from joining another branch?

Our working company, Git, works as follows: we have a branch master, some branches feature/*for developing new functions that were merged back to masterwhen the work was completed, as well as release/*branches, These branches are created before the release of the product and are designed to correct errors, without a new function, and these bug fixes are then periodically merged into a branch master.

From time to time, it happens that a particular commit in a branch release/*is a change that we don’t want to merge back onto master: for example, when the release number increases. Since there are other important fixes in the industry, surely someone will sooner or later turn this local commit on master, breaking something in the main branch.

The current "solution" that I know of is to merge the branch release/*in masterimmediately after the local commit, return the local commit, and then click. This is a kind of work, but the story is not clear. In addition, this does not prevent the local commit from joining into a different branch than master.

Is there a better way to solve this problem in the described workflow?

+4
source share
2 answers

As far as I know, it is impossible to merge into a commit without merging in all of your parent commits, which is similar to what you are trying to do.

However, a small change in the workflow can solve this problem.

Like the Git Flow model , you can create a branch hotfix/*to fix the error, instead of directly linking to release. Probably, this branch should be based on master(at the first commit, which is the parent of any corresponding branches release), and it should be combined in master, as well as with any branches release./p>

Thus, branches releaseshould never be merged in masterand can be reserved for release-specific fixes.

+3

release/* (.. ), - master, ?

0

All Articles