Mercurial revset selecting up to a bookmark

183 views Asked by At

If I have this changesets in my repository

A --> B --> C --> D
      *

B is bookmarked and D is at the tip - how do I create a revset that will select everything between B and D but not B.

Specifically I'm trying to squash C and D in to B, something like :

hg strip -r "bookmark:." -k

except this line will also delete the commit B which I want to keep.

2

There are 2 answers

2
Reimer Behrends On BEST ANSWER

I'm not entirely clear whether you want to squash C and D, creating a new commit C', or whether you want to squash B, C, and D, creating a new commit B', which will keep the original bookmark.

For the first:

hg rebase -s 'children(bookmark)' -d bookmark --collapse -m <msg>

You need to specify a commit message with either the -m or the -l option, or you'll get dropped into the editor.

For the second:

hg rebase -s bookmark -d bookmark^ --collapse -m <msg>

For a revset to specify all descendants of a revision, excluding the revision itself, use the following revset:

children(bookmark)::

Note that a non-linear history at this point can create unexpected results (in particular, the use of children() here assumes only a single child revision).

Remember to enable the rebase extension in your hgrc file for this.

1
elixenide On

You can use the histedit extension to achieve this. Simply type hg histedit c561b4e977df (where c561b4e977df is the hash of revision B in your example). Then type fold next to revisions C and D in the editor that pops up. This will collapse revisions C and D into B.