Updating Your Patches When the Underlying Code Changes

It’s common to have a stack of patches on top of an underlying repository that you don’t modify directly. If you’re working on changes to third-party code, or on a feature that is taking longer to develop than the rate of change of the code beneath, you will often need to sync up with the underlying code, and fix up any hunks in your patches that no longer apply. This is called rebasing your patch series.

The simplest way to do this is to hg qpop hg -a your patches, then hg pull changes into the underlying repository, and finally hg qpush hg -a your patches again. MQ will stop pushing any time it runs across a patch that fails to apply during conflicts, allowing you to fix your conflicts, qrefresh the affected patch, and continue pushing until you have fixed your entire stack.

This approach is easy to use and works well if you don’t expect changes to the underlying code to affect how well your patches apply. If your patch stack touches code that is modified frequently or invasively in the underlying repository, however, fixing up rejected hunks by hand quickly becomes tiresome.

It’s possible to partially automate the rebasing process. If your patches apply cleanly against some revision of the underlying repo, MQ can use this information to help you to resolve conflicts between your patches and a different revision.

The process is a little involved:

  1. To begin, hg qpush -a all of your patches on top of the revision where you know that ...

Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.