Overwriting branch with default in Mercurial

2019-07-23 07:23发布

问题:

Let say I had a feature branch called feature_x that was worked on, then changesets cherry-picked and transplanted to default, then the branch was closed. Not the best flow, but it's Mercurial, so there is no way of changing the history.

Now I'm going to work again on the feature X, and I feel reusing feature_x branch would be least confusing. However, if I reopen that branch and merge default to it, I've got two problems. First merge conflicts, second changes that were modified in that branch, but never merged into default. So what I'd like to have is clean slate, branch feature_x, but with exact copy of what's currently in the default. Is there a cleaner way of doing that, than creating new branch which will shadow the name?

回答1:

I think your best bet is to start a new branch off of the current tip of default called feature_x2 or feature_y and leave the past in the past.

But here are some other options:

  1. Is the old feature_x branch confined locally to your repo only or was it pushed? If the former, you could hg strip it and start the branch again at the current default.

  2. If the feature_x name is really, really important, you could do the merge default into it using the internal merge tools and force it to reflect the default branch exactly by doing

    hg merge -r default --tool internal:other
    
  3. Or you could just commit a (file system) copy of default on top of the tip of branch_x. Then you could continue on that branch along your merry way.

I don't know if 2. or 3. will cause strange merge issues down the road. I would test to see if the merge back over to default (or another graft?) could cause issues later.