Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>tl;dr: My original explanation looks complicated, but I hope it fully explains how to use a patch queue. Here's the short version:</p> <pre><code>$ hg qnew -m "migration notes" -f migration my_migration.sql $ hg qnew -f working-code # make some changes to your code $ hg qrefresh # update the patch with the changes you just made $ hg qfinish -a # turn all the applied patches into normal hg commits </code></pre> <hr> <p>Mercurial Queues makes this sort of thing a breeze, and it makes more complex manipulation of changesets possible. It's worth learning.</p> <p>In this situation first you'd probably want to save what's in your current directory before pulling down the changes:</p> <pre><code># create a patch called migration containing your migration $ hg qnew -m "migration notes" -f migration.patch my_migration.sql $ hg qseries -v # the current state of the patch queue, A means applied 0 A migration.patch $ hg qnew -f working-code.patch # put the rest of the code in a patch $ hg qseries -v 0 A migration.patch 1 A working-code.patch </code></pre> <p>Now let's do some additional work on the working code. I'm going to keep doing <code>qseries</code> just to be explicit, but once you build up a mental model of patch queues, you won't have to keep looking at the list.</p> <pre><code>$ hg qtop # show the patch we're currently editing working-code.patch $ ...hack, hack, hack... $ hg diff # show the changes that have not been incorporated into the patch blah, blah $ hg qrefresh # update the patch with the changes you just made $ hg qdiff # show the top patch's diff </code></pre> <p>Because all your work is saved in the patch queue now, you can unapply those changes and restore them after you've pulled in the remote changes. Normally to unapply all patches, just do <code>hg qpop -a</code>. Just to show the effect upon the patch queue I'll pop them off one at a time.</p> <pre><code>$ hg qpop # unapply the top patch, U means unapplied $ hg qseries -v 0 A migration.patch 1 U working-code.patch $ hg qtop migration.patch $ hg qpop $ hg qseries -v 0 U migration.patch 1 U working-code.patch </code></pre> <p>At this point, it's as if there are no changes in your directory. Do the <code>hg fetch</code>. Now you can push your patch queue changes back on, and merge them if there are any conflicts. This is conceptually somewhat similar to git's rebase.</p> <pre><code>$ hg qpush # put the first patch back on $ hg qseries -v 0 A migration.patch 1 U working-code.patch $ hg qfinish -a # turn all the applied patches into normal hg commits $ hg qseries -v 0 U working-code.patch $ hg out migration.patch commit info... blah, blah $ hg push # push out your changes </code></pre> <p>At this point, you've pushed out the migration while keeping your other local changes. Your other changes are in an patch in the queue. I do most of my personal development using a patch queue to help me structure my changes better. If you want to get rid of the patch queue and go back to a normal style you'll have to export your changes and reimport them in "normal" mercurial.</p> <pre><code>$ hg qpush $ hg qseries -v 0 A working-code.patch $ hg export qtip &gt; temp.diff $ rm -r .hg/patches # get rid of mq from the repository entirely $ hg import --no-commit temp.diff # apply the changes to the working directory $ rm temp.diff </code></pre> <hr> <p>I'm hugely addicted to patch queues for development and <code>mq</code> is one of the nicest implementations out there. The ability to craft several changes simultaneously really does improve how focused and clean your commits are. It takes a while to get used to, but it goes incredibly well with a DVCS workflow.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload