lujop
lujop

Reputation: 13873

Merge only one changeset from another branch

I'm new to mercurial and I read that it's not possible to merge only a separate changeset from another branch. Then I don't know what's the best approach to solve that:

  1. I start with an stable revision R1
  2. I continue developing on R1: CS1,CS2,CS3
  3. At some point I need to solve bug from my stable revision R1. And I want to apply only one changeset from developing line (fe CS2)

What's the best aproach? As merging didn't work what I've done is make a patch of CS2 and then apply the patch in the new stable branch to fix the bug. That's the Mercurial way?

Cheers,

Upvotes: 13

Views: 10999

Answers (2)

Larzan
Larzan

Reputation: 9667

UPDATE: No need for any extension anymore as of Hg 2.0

As 'CAD bloke' pointed out, this is exactly what the graft command is for which was introduced in Hg 2.0.

SourceTree

The easiest way to do this is with a GUI like SourceTree, just double-click on the TARGET branch to switch, then press the right mouse button on any other revision and select the 'Graft' command (strangely it can also be a revision of the current branch). If there are no conflicts SourceTree will immediately create a new revision for the current branch.

TortoiseHg

Exactly the same, select TARGET Branch, then rmb over the revision you want to graft: How to graft with TortoiseHg

Command Line

To do this with the command line just switch to the TARGET branch and then execute

hg graft -r {revision_number}

with {revision_number} obviously being the number of the revision you want to incorporate into you current branch. This will create a new changeset in you current branch with all the files from the revision whose number you used in the command.

To find out more about the graft command read this thread here on stackoverflow

Upvotes: 13

Idan K
Idan K

Reputation: 20881

The transplant extension automates what you've done to a single command.

But I think the preferred way (which depending on the scenario isn't always possible) is to make the fix on top of R1 in the first place, and then merge that to your development tip.

That is:

  1. Start with stable revision R1.
  2. You do some work, cs1...csN.
  3. An important fix is needed for stable on top of R1, so you hg update R1.
  4. Do the fix, this yields R2.
  5. Go back to where you left off, hg update csN.
  6. Merge stable so you have the fix, hg merge R2, hg commit...
  7. Continue working on csN+1.

Upvotes: 8

Related Questions