1

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.

Rafael Munitić
  • 897
  • 2
  • 9
  • 21

2 Answers2

2

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.

Reimer Behrends
  • 8,600
  • 15
  • 19
  • >Note that a non-linear history at this point can create unexpected results - What do you mean by this - is it undefined ? – Rafael Munitić Jun 08 '15 at 16:19
  • It means that (1) different commands may deal differently with revsets that have multiple head or tail revisions (2) you may have to (e.g.) specify how to merge with rebase (using `--tool`) or (3) may have to think about how to filter `hg export` output to `hg import --no-commit`. It depends on what exactly you're planning on doing. – Reimer Behrends Jun 08 '15 at 18:09
1

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.

elixenide
  • 44,308
  • 16
  • 74
  • 100
  • I'm trying to use this from python client api for command server so I'm not sure how I would go about "typing fold next to revisions" :) I think it would be simpler to manually walk the log output probably I just wanted to see if there was a simpler way. – Rafael Munitić Jun 07 '15 at 23:43