Maintaining a branch that does not contain commits associated with a specific change
I am working on a project with Git and have come to the point where I would like to split development into two separate branches. The split is about a simple change (with capital C, so I can come back to it later) that touches on one isolated piece of the codebase - on one branch, I want Change to be present; in the other, no. The change is wrapped in one commit.
In the branch master
where I do all my coding (unless a specific topic appears), this is the branch I want to change to. I would like to create a separate branch original
(or whatever you want to call it) that does not contain the change.
master
the branch with the change will remain the main, preferred branch: on the branch, I will continue coding, and that's the branch that I am actually executing. I want to save original
just in case I need a version of the code without the above change later.
Here's the problem: I would like to be able to "merge" work from master
in original
on the way, but obviously only commits that don't touch the change.
- If I make it simple
git merge master
, itoriginal
goes into modemaster
by introducing a change I didn't want, right? - I do not want to develop on
original
and merge withmaster
, because thisoriginal
is a special case, notmaster
. - I don’t want
cherry-pick
outmaster
, because it will confuse my development history. - I can create a new branch
develop
from the command that types Change inmaster
. I could commit non-change commits on this branch and merge them intomaster
or easilyoriginal
. However, if I make some change-related commits tomaster
and want to merge them intodevelop
, then I can't safely mergedevelop
into againoriginal
, right?
I would like to know your opinion on the best way to proceed.
EDIT: I'm the only person working on this project, so don't rule out a solution, because it might mess up other programmers in a collaborative environment. I'm just looking for an easy-to-use solution that creates a clean , intuitive story that captures what these different development stories really are.If no such solution exists, I'll accept one of the answers that follow.
source to share
I liked the fourth approach:
I would recommend that you create another branch hotfix
from which you created the branch original
. Both branches will not contain Change
associated commits, and you can safely merge them into a branch master
and original
.
If you want to merge some related Change
commits into master
c hotfix
then create a branch hotfix-with-change
from hotfix
and merge it there.
If you want to develop unrelated code Change
that will affect original
and master
, do so in hotfix
and don't forget to update the branch as well hotfix-with-change
.
If you want to develop related Change
code, your branch must be a branch master
, and if you want to see it make a mistake in original
, you need to merge it with hotfix-with-change
.
Hope this was clear.
source to share