We have been working on a work branch for some time now, with the intention of bringing it back to my main branch at some point.
In the mean time, that work branch has been kept up-to-date by frequent merges from the main branch.
Now it turns out we only want to bring some of the changes from that work branch, but not yet all, to the main branch.
What is difficult here, is that those changes are not at all nicely separated by commit or by file, because it was never expected to have to do this. Instead, individual commits bring changes we want on my main, as well as changes we don't want on my main branch. It possible to see instances of both kinds of changes within any given single file.
Now, there is still a possibility that in the end, we will want to merge that work branch definitively back in the main branch, as originally planned. So I need to keep this possibility open, and it needs to offer a good guarantee that everything has indeed been merged as planned - or at least a good way to check.
Because of that, it feels that git cherry-pick
(assuming it can go down to the level of individual hunks within files) is not the option I want, because then all the original commits from the work branch on the one hand, and the commits generated by cherry-picking on the main branch on the other hand will all be dumb conflicts where it will look like both branches bring the same change. Also the log will look totally ugly with duplicate log comments.
I would much rather have a single commit saying "Bring all changes related to X and Y but not Z from work branch.". And then sometime later, if we so choose, another commit saying "Bring remaining changes from work branch, mainly about Z.". I guess ideally that last one would have the two parents, but I don't know what would be ideal for the first one : should it have some commit in the work branch as its parent ? So merge
-like rather than cherry-pick
-like.
At the same time, if I decide to go for an actual merge
to create the first commit, I will have to manually remove stuff in the code on the main branch to ignore changes about Z that would have come from the work branch via this merge
. However, since that first commit would have the tip of the work branch as one of its parents (this being an actual merge
), it would appear to git that that first commit contains all the changes from the work branch - but that wouldn't be true.
It may be that I put myself in a situation that git cannot solve cleanly or natively, and if that is the case, I would like to know, and I would be fine with it. I would still be interested in other degraded solutions which would break some of my requirements.