As landing multiple patches together has become common practice on mozilla-central, we've started a semi-official policy of requiring people to back out all of the changesets in their push if something breaks.  This is a good thing, because mozilla-central is not a very good place to test bustage fixes, and it helps the tree to get to a good state very soon.

However, when you want to back out multiple patches in a push, backing them out individually using hg backout is a real pain, it basically means that you have to merge N times if you have N patches to back out.  There is an easy way to back out multiple patches in Mercurial though, and I've been asked about this by people in IRC several times recently, so I figured I'd blog about it since people seem to need it.

Let's say you've pushed N consecutive changesets, with the first one having the changeset ID cset1 and the last one having the changeset ID csetN.  You also need to know the the ID of the parent changeset for cset1.  Let's call that csetP.  To back out everything from cset1 to csetN (inclusive), you should do something like this:

hg pull # make sure you have a recent tree
hg update csetN # update to the last changeset in the range
hg revert -a -r csetP # revert to the parent of the first changeset
hg commit -m "Back out bug xxxxxx, bug yyyyyy, ..." # commit the backout
hg merge # if csetN is the repository's tip, merging is not necessary
hg commit -m "Merge backout, a=bustage fix" # commit the merge
hg push # push the backout