mpen
mpen

Reputation: 283325

How can I update to the end of the current unnamed branch?

I thought hg update (with no arguments) would move me to the end* of the current [unnamed] branch, but I believe it will try crossing branches if the other one is newer, which is not what I want to do.

* I'm deliberately avoiding the word "tip" because "tip" refers to the most recent revision, regardless if that named branch has two or more heads.

I'll give some example.

     2       4 (tip)
      o------o
     /
o---o
     \
      o---o
     1    3

I'm at 1, but I want to update to 3 (the end of the branch I'm on). If I type hg update with no arguments it will actually error with the message "abort: crosses branches (merge branches or update --check to force update)". In some scenarios it might even say "abort: not a linear update (merge or update --check to force update)" but I'm not quite sure what triggers that (if you know, please tell me).

If I do hg update --check it will move me to 4 (the tip of the current named branch), which is not what I want either.

I can check hg log to find out the changeset for 3 and then hg up 3, but I would like to do it in one command because trying to understand the log is tedious.

Perhaps revsets could be of use, but I don't know which one would help me.

So, how can I update to the end of the current unnamed branch?

Upvotes: 2

Views: 2875

Answers (1)

Ry4an Brase
Ry4an Brase

Reputation: 78350

A plain hg update tries to take you to 4 (not 3) because it always tries to take you to the newest (technically "most tipward") revision on the requested branch, or default if unspecified. So it doesn't matter if you're on 0, 1, or 3, hg update is always saying take me to 4 with the graph above (assuming all revisions are on the same named branch).

Your revset to take you to the greatest descendent of your current revision is great, but if you find yourself navigating between multiple heads on the same named branch often consider dropping a bookmark on each of them. A bookmark is like a tag that auto-advances on commit, so if you do:

hg bookmark -rev 3 mybranch
hg checkout mybranch

you'll end up with the 'bookmark' mybranch that will always move forward as new child changesets are added, and you can always get back to it with hg checkout mybranch

Upvotes: 3

Related Questions