Joymaker
Joymaker

Reputation: 1426

Use graft to transplant the content of one branch to another?

Forgive me, this may well have been asked before, but I can't find my way through all the complicated options to the simple thing I want to do.

On my default branch I do primary development. A while back I created a "beta" branch (now at version 160) to allow a beta tester to work on a stable version, while primary development continued. (now at version 200)

Now it's time to update the beta branch to equal the content of the default branch as it now is. No merge, no fancy discussion, just full-on replace whatever is in the beta branch with whatever is now at the tip of the default branch. Is this a job for graft?

I see a lot of discussion about moving "commits" from one branch to another, but does that mean the same thing as moving the entire content if I use the latest commit?

A command line example would be most helpful.

Upvotes: 0

Views: 643

Answers (1)

torek
torek

Reputation: 488975

I posted a close-request-link to a likely duplicate (Mercurial: make one branch identical to another) but I thought I would add the following...

Grafting is definitely not what you want here. Grafting means copying a changeset, or some number of changesets, from one branch or thread-within-a-branch1 to another.

It is possible to use hg merge to copy a different branch's tip commit (or any non-tip commit, really) to your own branch using the :other built in merge-tool.2 This records an actual merge, unlike the other answer's close-and-reopen method. There's no particular reason to favor one method over the other.


1It's not clear what to call these. Edit: Mercurial documentation calls these anonymous branches. You get them when you use Mercurial in a more Git-like fashion, using bookmarks to keep track of multiple heads within a single named branch:

                  c4--c5   <-- bookmark1
                 /
default:   c1--c2--c3   <-- bookmark2
                     \
                      c6--c7--c8   <-- bookmark3

In Git, these bookmarks are the branches: there are no permanent branches at all, and all you get are bookmarks.

(Side note: it's not clear if Mercurial considers c3 an anonymous branch. Commit c3 is not a head, and will not be listed by hg heads, even though it has a bookmark identifying it. The anonymous branch effectively sprouts later, if and when you update to the bookmark and then create a new commit, dragging the bookmark along to track its progress.)

2This is the equivalent of Git's missing -s theirs merge strategy. Compare with :local, which is the equivalent of Git's -s ours strategy, and contrast tis with :merge-local or :merge-other, which merge changes from both sides, but favor our or their side for automatic merge conflict resolution.

Upvotes: 1

Related Questions