4

What is the best way to abandon unwanted changesets currently in a Mercurial topic, which have already been pushed and cannot just be stripped?

To put the question another way, is is possible to remove a topic from the hg topics output without publishing it?

mforbes
  • 7,062
  • 3
  • 16
  • 21
Rob Agar
  • 12,337
  • 5
  • 48
  • 63

1 Answers1

4

hg prune -r "topic(some-topic-name)" will mark all revisions marked with the topic some-topic-name as obsolete locally

hg push --hidden should then mark them as such in the remote repository. --hidden is not always required.

Anthony Williams
  • 66,628
  • 14
  • 133
  • 155
  • 1
    AFAICR, `-r ${topic}` will delete only topic's head and you have to repeat this operation more times for each changeset. But pruning first changeset of topic will do it in single action (may be wrong) – Lazy Badger Jan 06 '20 at 11:47
  • Yes you're right @LazyBadger using `-r "topic(${topic})"` prunes them all though. Also you can use `-r "topic(my-cool-topic-name)"` to avoid checking out the topic itself. – Will S Jan 14 '20 at 10:20
  • I'm not sure if this is Will's point but I've found `hg prune -r "topic(${my_topic})" prunes **all** existing topics, which is probably not required. – Charlie Clark Apr 22 '21 at 13:50
  • `${my_topic}` is a shell expansion of the `my_topic` variable. If it is not defined, it will yield blank, so the command would expand to `hg prune -r "topic()"`, which will indeed prune all topic revisions. – Anthony Williams Apr 23 '21 at 13:05
  • Note that `hg push` won't report that the topic was obsoleted in the remote. Also, you may encounter trouble if `push` is pushing more than this abandoned topic. More selective would be to push the parent of the commit off of which the topic was based (or any public descendant), e.g. `hg push -r default` if the topic was based on a commit in default. – Jason R. Coombs Apr 10 '23 at 15:34