Fix bad merge in mercurial

烈酒焚心 提交于 2019-12-23 17:18:47

问题


In our mercurial project configuration we have 3 branches in a single repository. 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.

We have merged a whole load of new feature code into the UAT branch without any issues at all. 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. I have discovered that this problem has been caused by someone merging UAT into stable a while ago (which should have never happened!!). Now when I try to merge the bug fixes into UAT it removes all the new feature code.

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'? 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.


回答1:


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. 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. (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!

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.



来源:https://stackoverflow.com/questions/7825269/fix-bad-merge-in-mercurial

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