3

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.

smithy
  • 61
  • 5
  • 2
    You've verified that nobody has accidentally added some of those files to the stable branch, and subsequently deleted them? Or a folder containing those files? – Lasse V. Karlsen Oct 19 '11 at 17:18
  • No. The files have not been removed because they have never existed on that branch. – smithy Oct 20 '11 at 09:15
  • What version of Mercurial are you using? – Laurens Holst Oct 20 '11 at 09:42
  • Very similar question here btw: http://stackoverflow.com/questions/7833175/critical-mercurial-merge-has-unexpectedly-deleted-source-files – Laurens Holst Oct 20 '11 at 10:02
  • 1
    Think I have found the issue. I was incorrect when I said that these files have not been added and deleted. From looking at the repository explorer it appears as though someone has merged in the wrong direction which has dropped files from the feature branch. We have done a load of changes since on stable and now when we do the merge the correct way we get the issue. Does anyone know of a good way to recover from this kind of error? – smithy Oct 20 '11 at 11:47
  • Smithy, please alter your question with your new findings. No one wants to answer the new one in a comment hanging off one you've found to be inaccurate. – Ry4an Brase Oct 20 '11 at 14:03
  • I've updated the question and clarified the situation – smithy Oct 21 '11 at 12:02

1 Answers1

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.

smithy
  • 61
  • 5
  • +1 your solution reminds me of my merging of two unrelated repositories (http://stackoverflow.com/questions/6889750/how-to-adjust-history-after-merge-of-two-unrelated-mercurial-repositories). I like your solution. – hochl Oct 24 '11 at 12:40