Reputation: 474
1 -- 2 -- 3 --------- 7 C
\ \- 4 / B
\------------5----/ A
I ended up with the branching structure above in my mercurial repository. What I really want is for commits 2 and 3 to be on branch B, as below:
1 -- 2 -- 3 -- 4 B
\ ------------5 A
Is there a good way to retroactively get this structure?
Upvotes: 1
Views: 56
Reputation: 487725
I'll disagree a bit with DaveInCaz's answer, but in the end, agree with the conclusion: you should be able to live with what you have; it's fine.
Technically, in Mercurial, once you make a commit, it's on exactly one branch and the branch it is on is the one branch you were on when you made it. So if you were on branch C
and made commits 2 and 3, commits 2 and 3 are on branch C
, now and forever.
But that doesn't really matter in terms of getting work done. Commit 4 is on branch B
, and commit 4's parent is commit 3
, whose parent is commit 2
. The fact that they are on some other branch is normally unimportant.
(This setup is quite different from Git: in Git, commits are on all the branches from whose tips they are reachable. Branch tip names can be created and destroyed whenever you like, pointing to any existing commit. This means that the set of branches that some commit is on changes from one day to another. In effect, branch names in Git are devoid of any intrinsic meaning. You can add, remove, or change any name any time. The commits don't change but the set of branch names that reach them do.)
If, for some reason—e.g., some external tool that demands that the branch name of the commits be B
rather than C
—you really do want or need to move these commits, the answer is that you can't actually move them at all, but you can copy them:
C: 1 -- 2 -- 3 --------- 7
B: \ \- 4 /
A: \------------5----/
can become:
C: 1 -- 2 -- 3 ------------------ 7
|\ \ /
B | \ 4 /
B: | \ /
B | -------- 2b - 3b - 4b /
\ /
A: ---------------------- 5
Note that having copied 2
to 2b
and 3
to 3b
, you must now also copy 4
to 4b
. Both 4
and 4b
are on branch B
, and branch B
now has two heads.
As DaveInCaz noted, you can strip the unwanted commits. If they exist in some other clone that you talk to, they'll come back every time you talk to that clone, unless you strip them there as well.
Upvotes: 1
Reputation: 12988
You already have the structure you want, except that 7 has been added on top of it.
If 7 has not been pushed anywhere (or at least, not to any clones you don't control) you can just hg strip
it.
If 7 has been pushed publicly, you can no longer remove it with strip
because other clones will still have it. But you can ignore it, and just continue working from 4 or 5 as you please. No changes need to be committed with 7 as a parent.
Upvotes: 0