Feature backporting in Git / Subversion

不羁的心 提交于 2019-12-04 03:16:22

The all idea of backporting features looks broken for me. Only critical and non-destructive changes should be backported. For features and improvements you have to create new branch and start stabilization period.

Check out release process used in Apache Subversion project itself: https://subversion.apache.org/docs/community-guide/releasing.html#release-stabilization

It depends. If the critical feature is relatively simple and small, you could just make several cherry-picks. However, of course it could cause a lot of merge conflicts, because the implementation of the feature could use the refactored code. However, as I understand it will be easiest solution. And only solution for SVN.

However this solution doesn't reflect actions in the history graph, it confuses.

With git there is another option to rebase the critical feature at the merge-base of the master and the release-2.0.x branches. It literally means that you should reimplement the feature using old code, which is common for both branches. In this case you then could merge the rebased feature. If you have merged the feature to the master already, when you would merge rebased feature into the master, it most probably will conflict (becasue master already has such implementation). So you will resolve conflicts, however in most cases it will be easy, because changes should be nearly the same.

The good thing about the rebased feature approach is that if you would find a bug in it, you could fix it in the feature branch and easily merge fixes into the release and the master branches.

Of course, the rebasing could cause a lot of conflicts, but it means there is no easy way to backport the feature into the release-2.0.x. Maybe it would be easier just re-implement it then.

I have developed some tools specifically for making this process easier with git, and last week I wrote an extensive blog post about them. In particular, the git cherry-menu command referenced in that post can accept an arbitrary list of commits to backport, so using git log and your favourite text editor, you could build a reasonably carefully selected list of commits which constitute the critical feature to be backported, and then run something like:

git checkout -b release-2.0.y release-2.0.x
git cherry-menu cat commits-to-backport.txt

This is similar to kan's rebasing suggestion, except that the backporting process is more structured, and by using git notes under the hood, you get several handy extra features, including that all meta-data describing the process is persisted across multiple runs of git cherry-menu.

Of course, if you only have a handful of commits to backport, kan is right that you might as well just cherry-pick directly.

Unfortunately I think the accepted answer is slightly self-contradictory:

The all idea of backporting features looks broken for me. Only critical and nondestructive changes should be backported. For features and improvements you have to create new branch and start stabilization period.

because creating a new branch and starting a stabilization period is still backporting. The only difference is which branch you decide to put the backported commits into! You can either put them into the original release-2.0.x branch, or a different branch forked off it, like the release-2.0.y branch I suggested above. It's generally safer / cleaner to do the latter (and I guess that's Ivan's point), but really that depends on how you organize your repositories and branches. It still doesn't avoid the need to perform cherry-picking and potential conflict resolution though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!