Git:主要版本更改的分段合并方法? [英] Git: piecewise merge approach for major version changes?

查看:83
本文介绍了Git:主要版本更改的分段合并方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在对网站进行重大修订.修改后的站点上的所有工作都是在git分支(称为2.0)中完成的,该分支是一段时间前从master分支出来的.在此过程中,已经掌握了一些较小和重要的更改,我们希望将这些更改合并到2.0中.

We are working on a major revision to our website. All of the work on the revised site is being done in a git branch (call it 2.0), which branched off from master some time ago. Along the way, some changes, both minor and significant, have been made to master, and we'd like to merge those change in to 2.0.

但是,作为一个大的合并来完成它似乎很麻烦-尽管某些更改可以很好地合并,但其中一些更改涉及的代码不再存在于2.0中,并且本质上将要求重新实现2.0的新功能.只要合并后仍然存在许多未解决的冲突,修复这些功能可能就很困难.我们已经考虑过使用cherry-pick从master那里带来那些可以很好地合并的更改,同时手动重新实现主要更改,但是如果我们想将2.0中的所有更改合并回给我,那将会造成麻烦.大师.

However, doing it as one large merge seems unwieldy--while some of the changes will merge nicely, some of them involve code that no longer exists on 2.0, and will essentially require reimplementing new features on 2.0. As long as there are bunch of unresolved conflicts after the merge, fixing those features might be quite difficult. We have considered using cherry-pick to bring only those changes from master that will merge nicely, while manually re-implementing the major changes, but I'm that will cause trouble if we ever want to merge all of the changes in 2.0 back to master.

理想情况下,我可以从master到2.0进行分段合并-将一组次要提交合并到一个特定提交,然后合并一个主要提交并手动重新实现特定的新功能,然后再实现另一个系列最后,母版完全合并到2.0中.这是解决这种情况的好方法吗?如果是这样,我该如何部分合并到master中,而不是一直合并到最新的master提交中?还是我应该采用其他更好的方法?

Ideally, I could do piecewise merges from master to 2.0--merge a group of minor commits up to a particular commit, then merge a single major commit and manually re-implement a particular new feature, then another series, in such a way that at the end, master is fully merged into 2.0. Is this a good approach for this situation? If so, how do I merge partway into master, rather than all the way up to the most recent master commit? Or is there some other, better approach I should be taking?

推荐答案

您当然可以通过引用提交哈希而不是分支名称来合并在分支中.因此,假设您要合并到master行上的特定提交–假设它是abcd1234 –您只需进入您的2.0分支并运行:

You can certainly merge in a branch piecemeal by referencing a commit hash rather than a branch name. So say you want to merge up to a particular commit on the master line – let’s say it’s abcd1234 – you can simply get onto your 2.0 branch and run:

git merge abcd1234

使用这种方法,您可以一次执行任意多次提交.如果您遇到冲突,则可以立即解决该冲突,而不必立即进行处理.

Using this approach, you can then take as many or as few commits at a time as you like. If you get a conflict, you can just resolve that one conflict without having to take it all on at once.

如果您在master分支上进行的更改仅与分支上不存在的代码相关,因此完全过时,则可以运行:

If you have changes on the master branch that you know solely relate to code that doesn’t exist on your branch, and are therefore entirely obsolete, you can run:

git merge --strategy=ours bcde2345

这将为master上的更改创建合并提交,但不会更改树的内容与2.0上的内容相同,因此这些提交将被标记为已合并,而无需实际执行任何操作.

This will create a merge commit for the changes on master, but will not change the contents of the tree from what they are on 2.0, so the commits will be marked as merged without actually doing anything.

这篇关于Git:主要版本更改的分段合并方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆