简体   繁体   中英

Create new heads in mercurial

In my current workflow whenever I need a branch I use bookmarks, but in order to create a new head from the current revision I have to commit some dummy changes and go back one revision, then commit to that, otherwise the commits will be made to the same head, no matter how many bookmarks I had.

For example, suppose I'm on rev 40:

hg bookmark main
hg ci somefile -m 'dummy commit' # on rev 41 now
hg up -r 40
# make some changes
hg ci -A -m 'changes in bookmark' # created new head
hg bookmark test

Is this common or there's some shorcut to force the creation of a new head?

I think you want to practise nvie's workflow, so you want to merge with up-stream with --no-ff.

So far as I can recall, hg doesn't support merge with up-stream in the same branch. As this post said, hg's head/bookmark is git't branch, while hg's branch is lineage.

Therefore, the solution is at the forking point, you change both bookmark and branch, then later you can merge the branch because they are different lineage.

You can easily hg branch -f dev in my example, reopen the branch even they are not connected.

So you can have branches like:

  • default
  • stable
  • feature
  • hotfix

Then the bookmarks should be prefix as:

  • feature-*
  • hotfix-*

And they should be branched off corresponding branches.

Then they can be

我的示例的Graphlog

There is no need for a second head to be created in your example and you shouldn't force its creation.

The advantage with your workflow is that you can stop work on feature test to do a more urgent change on the main branch like this:

> hg bookmark main
> hg bookmark test         # Start work on feature test

 ... do some code ...

> hg commit -m "Working on feature test"
> hg update main           # Stop working on test, start working on main

 ... do an urgent fix ...

> hg commit -m "Urgent fix"
> hg update test           # Back to work on feature test

 ... do some more code ...

> hg update main           # Finished the work so back to main
> hg merge test            # Merge the work into main
> hg commit -m "Merge in feature test"

When that's done, you will have completed the new feature and merged it back into the main development branch.

If you don't make any changes to the main branch when you have finished working on feature test then you can't merge the changes in as you can't merge a changeset into an ancestor so you would need to move the main bookmark to the test bookmark as follows:

> hg update test
> hg bookmark main -f

(I believe that this is called a fast-forward merge in git and that you can force the merge if you want but there is no mercurial equivalent as far as I know)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM