Mercurial - How to push current changeset to default branch

1.5k views Asked by At

I'm not sure why this is so hard to figure out or google, but I am trying to take changes I made to a private branch and push them to the default branch.

In other words:

  1. I pulled from the default branch a few weeks back and made major changes
  2. Since then, I have finished my work
  3. I then merged the code from the original default branch (just the code, the HG is still set to the "NewBranch"
  4. Now that the code works, I want to commit and push these changes back to the default branch and continue my development from there.

But I can't find any information on how to do that. If I switch branches, I lose all my changesets since I am still in the NewBranch. I can't figure out what rebase or transplant do and can't find guides that explain scenarios on what they could be used for... So hopefully someone here knows what to do!

I am specifically using Mercurial on Eclipse but I am fine doing this on command line if its easier.

1

There are 1 answers

1
Ry4an Brase On BEST ANSWER

merge is the way to get changes from one branch into another. I know you merged default into feature, but now you go the other way. Here's an example where numbered changesets come from other people and lettered changesets comes from you:

Before you do anything you clone and have this:

[1]---[2]---[3]---[4]   (default branch)

then you create your branch named 'feature' and do two commits on it, yielding:

[1]---[2]---[3]---[4]           (default branch)
                    \
                     [A]---[B]  ('feature' branch)

then you hg pull to get changes to default since you diverged down in your local repository:

[1]---[2]---[3]---[4]---[5]---[6]  (default branch)
                    \
                     [A]---[B]     ('feature' branch)

now you want their changes (5 and 6) integrated into your branch so you do:

hg checkout feature   # make sure you're looking at the he head of your branch
hg merge default      # merge default into your branch

which yields:

[1]---[2]---[3]---[4]---[5]---[6]        (default branch)
                    \           \
                     [A]---[B]---[C]     ('feature' branch)

If I'm understanding correctly, you've already done all that, so now you just need to bring your branch, including the new merge commit, C, into default, which again is done via a merge:

hg checkout default   # hop back to default, files look like [6] and [A] and [B] are missing
hg merge feature      # merge feature into default brining [A] and [B] in

that yields:

[1]---[2]---[3]---[4]---[5]---[6]---[7]   (default branch)
                    \           \   /
                     [A]---[B]---[C]      ('feature' branch)

That looks like a lot of work drawn out that way, but in practice it's usually just:

hg branch feature
....work....
hg commit
hg pull
hg merge default
hg checkout default
hg merge feature

and if the pull didn't bring down any new work from other you can skip the merging of default into yours.

That does create two new merge changesets. They're easily hidden on hg log if you find them unhelpful (some people love having a record of which direction each merge went), but if you want to avoid them entirely you can use bookmarks (very similar to git branches) instead of "named branches" for your features -- then you'll avoid a merge changeset when coming back since it would be the spiritual equivalent of what git calls a "fast forward" merge.