Search code examples
version-controlmercurialmercurial-queuemercurial-extension

How can one remove changesets from revision history of MQ repository?


I have a Mercurial repository. It has a patch queue (which itself is a repository containing patches). Unfortunately I have performed too many unsightly commits to MQ (with hg commit --mq command). If I run hg history --mq command, it will print tons of unnecessary changesets, say, A, B, B1, B2, B3, B4, C, D . I just want to get rid of those B1, B2, B3 and B4, but I don't want to remove the latest C and D . Just those intermediate changesets. How can I achieve the desired?


Solution

  • Assuming that there are no conflicts between the subsequent mq changesets, it's quite simple.

    The mq way is to use hg qdelete PATCH-ID with the patches you want to see removed. It is mandatory that the patches are NOT applied.

    Alternatively you can use the normal hg way to edit your mq repository:

    • unapply all mq changesets: hg qpop --all
    • Edit the .hg/patches/series file and remove the lines of the patches you want to see removed
    • check that all remaining patches apply cleanly, best done one by one, thus do a hg qpush for each. Should there be any conflict fix it now.
    • Commit the changes to the mq repository in .hg/patches

    Should you require one of the intermediate patches, check for hg qfold and friends.