简体   繁体   English

修复mercurial中的错误合并

[英]Fix bad merge in mercurial

In our mercurial project configuration we have 3 branches in a single repository. 在我们的mercurial项目配置中,我们在一个存储库中有3个分支。 One is a stable release branch where urgent bug fixes are done, one is a feature branch which contains new feature code and one is a UAT branch where both bug fixes and new features are merged into to provide the most up-to-date code base. 一个是稳定版本分支,其中完成了紧急错误修复,一个是包含新功能代码的功能分支,另一个是UAT分支,其中错误修复和新功能都合并到一起以提供最新的代码库。

We have merged a whole load of new feature code into the UAT branch without any issues at all. 我们已经将大量新功能代码合并到UAT分支中而没有任何问题。 Following that we merged the stable branch with the bug fixes into the UAT branch but this seems to have the effect of removing the new feature code. 接下来,我们将稳定分支与错误修复合并到UAT分支中,但这似乎具有删除新功能代码的效果。 I have discovered that this problem has been caused by someone merging UAT into stable a while ago (which should have never happened!!). 我发现这个问题是由一个人将UAT合并到稳定之前引起的(这应该从未发生过!!)。 Now when I try to merge the bug fixes into UAT it removes all the new feature code. 现在,当我尝试将错误修复程序合并到UAT中时,它会删除所有新功能代码。

Is there a way of removing the effects of the merge from UAT into stable, whilst still retaining the bug fixes that are descendents after this 'bad merge'? 有没有办法将合并的效果从UAT中移除到稳定中,同时仍然保留在这次“糟糕合并”之后作为后代的错误修复? I've tried backing out the merge but it seems to have no effect at all. 我已经尝试退出合并,但似乎根本没有效果。 Can I do a strip and re-add the required changesets back in? 我可以做一个剥离并重新添加所需的变更集吗?

Thanks in advance. 提前致谢。

I've actually managed to fix this one myself through a bit of trial and error. 我实际上已经设法通过一些试验和错误来解决这个问题。

First you need to enable the transplant and mqMerge extensions in your mercurial.ini file. 首先,您需要在mercurial.ini文件中启用移植和mqMerge扩展。 Add the lines following lines below the extension header 添加扩展标题下面的行后面的行

   transplant=
   mq=

Clone a your repository to a new location. 将您的存储库克隆到新位置。 In your new repo, remove the bad merge by using the strip command to clear history the effect of the bad merge is removed. 在新的repo中,使用strip命令清除错误合并,删除错误合并的效果。 (Beware that this will remove all descendent changesets) (请注意,这将删除所有后代更改集)

Then you need to cherrypick all the required changesets in chronological order from the other repo by using a command similar to below 然后,您需要使用类似于下面的命令,按照时间顺序从其他仓库中挑选所有必需的变更集

    hg transplant -s "otherRepo" -b "branchName" "changesetHexNumber"

Repeat the transplant command for all the required changesets. 对所有必需的变更集重复移植命令。 Ouila! Ouila!

NB: If you are using a central repository you will need to strip the offending merge/changset on there too otherwise your local repo will think you have outstanding changesets to pull. 注意:如果您使用的是中央存储库,则需要删除有问题的合并/变换集,否则您的本地存储库会认为您有未完成的变更集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM