Reverting Changesets With File Moves/Renames

Normally backing out a changeset in Mercurial is as simple as:

$ hg backout revision
$ hg merge
$ hg commit

Mercurial has a bug, however, when the revision being backed out contains file renames (moves). The backout will record the change as an add/remove, instead of a rename to the old location. Instead of using hg backout for these changes, use the following procedure instead.

Note: Benjamin Smedberg is more than happy to perform complex backouts, if these instructions are confusing or terrifying.

These instructions assume you're trying to back out revision X, and that the parent of X is XPARENT:

Preparation: Install and enable the move-fixup extension:

Clone or download

Enable movefixup in your Mercurial configuration file ~/.hgrc:

movefixup = /path/to/

Step 1: update to revision X

$ hg up X

Step 2: revert to revision BADPARENT

$ hg revert -a -r XPARENT

Step 3: Find and fix file moves

$ hg status -ar # -ar shows only files that were added or removed
A oldfilename
R newfilename

$ hg movefixup newfilename oldfilename

Step 4: Check your work

Before committing, read a diff-style git to make sure that file was renamed correctly. The diff should say something like:

diff --git a/newfilename b/oldfilename
rename from newfilename
rename to oldfilename

Step 5: Commit

Commit your backout changeset, and merge forward as necessary.