Search code examples
mercurialmercurial-queue

How to retrieve an accidentally deleted patch in Mercurial with MQ


I had two patches in series, neither one applied, and I accidentally called qdelete on the wrong one. Is there any way to reverse this operation and get my patch back? I had a huge amount of work in this one!!!


Solution

  • The way to avoid this (and I know it's not helpful now, sorry) is to not just use Mercurial Queues, mq, but to use it with a patch repository. Mercurial/mq has great support for this.

    When initially creating the queue you do:

    hg qinit --create-repo
    

    (instead of just hg qinit), which creates a new Mercurial repository in your .hg/patches directory. Then you can use:

    hg commit --mq
    

    to commit all your patch files, and bringing this back would be just a matter of:

    hg revert --mq
    

    The bottom line, and again I know it's not helping you now, but maybe it'll help the next guy or you later, is: if you're writing code and it isn't committed somewhere it doesn't exist -- commit and push early and often