views:

422

answers:

2

Basically, I have dev branch, and what I like to do is to create a feature branch while I implement something, and then merge it back. So situations like the following occurs

 a
 b
 c
 d - dev
/ 
e
f - feature

Since dev isn't a head, is it still possible to bring dev up to feature such that both dev and feature are pointing to f?

I'm pretty sure git can do this just fine, but can't seem to convince Mercurial to do the same...

+5  A: 

Named branches in hg (unlike in git) don't "point" anywhere. Branch names aren't movable aliases for a particular rev. Each commit has a metadata marker naming the branch that commit is on; that's all.

In this situation, if you have no separate commits descending from "d" on the dev branch, then all you need to do is run "hg branch dev" and then your next commit, descended from "f", will be back on branch dev. Which I think will achieve the results you're looking for.

EDIT: That will work, but Steve Losh's suggestion of doing an actual merge will result in a more sensible history.

Carl Meyer
+10  A: 

Carl Meyer is right. You're thinking as a git user, and Mercurial handles things differently.

You could do what Carl suggested and just force the next commit to be on the dev branch. I'd personally find this rather confusing if I saw it though, since there would be a discontinuity in the dev branch.

The way I'd handle it is to merge the feature branch back in: hg update dev && hg merge feature && hg commit -m 'Merge in the completed feature.'

This would result in a graph like:

  a - dev
  b - dev
  c - dev
  d - dev
 /|  
e | - feature
f | - feature
 \|
  g - dev

For me, this clearly illustrates exactly what happened. You branched off for a new feature and merged it into the dev branch when finished. The fact that there were no other commits on dev in the meantime is just a coincidence and doesn't have to change the workflow.

Steve Losh
Hm. I've been meaning to try to do your method, but I don't quite remember what I did wrong. Maybe i'll play around with it a bit more to see if I figure it out.Thanks both of ya!
Calyth
Hm. That worked. Thanks Steve!
Calyth