开发者

Merging some revisions but not others with Mercurial

I recently started tracking changes for my project with Mercurial. I made several revisions before I started working on a certain feature. Now, I want to go back to my revision before I implemented that feature and try implementing it a very different way. However, I want to keep some of the changes I made while working on the first implementation because they apply equally no matter what implementation I choose.

What's the best way to update back to the revision before I started implementing the feature, but selectively incorporate changes along the default branch into a new, separate branch? Is this the right way to 开发者_如何学运维merge/branch with Mercurial? If I do this, can I later "drop" one of those branches in favor of one particular implementation of this feature?


This is very easy if you have an external diff program like Beyond Compare.

  1. Enable the extdiff extension and configure it to use your diff program (e.g. I have my system set up so that hg bcompare will run Beyond Compare)
  2. Update your repo's working directory to the revision where you want to start the new branch.
  3. Use Mercurial to run your diff program against the head with the experimental changes.
  4. Cherry pick the changes you want from the experimental code, either whole files or smaller diffs within files.
  5. When you exit your diff program, your working directory will have the changes you picked.
  6. Start a new branch (hg branch) or set a bookmark (hg bookmark) to track this new set of changes against. See http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/ for a description of the differences.
  7. Commit the changes, and off you go!

When you decide which implementation you want, you can either update to the head of the branch you don't want and use hg commit --close-branch to mark it as closed, which still leaves it as a head in the repository. If you want to remove it as a head, update to the head of the branch you do want and use hg merge --tool internal:local <rev-of-the-other-head> to merge it, but keep all the wanted changes.


I know this question is a bit old, but I ran into something similar today when working on a project. I had spent a few days going down a dead-end trying out a feature on the default branch. Here's the process I used to get my code base back in a good condition.

  1. I updated back to the last good revision (in my case, R0!) via hg update -R 0
  2. I created a new branch for the feature (hg branch NEWFEATURE and hg commit)
  3. I started cherry-picking good commits from the other branch via tranplant (hg transplant -b default revNumberToPick)

Transplant is shipping in the box with mercurial now, and just requires you to enable it. The documentation is located on Mercurial wiki. Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜