Version 10 (modified by Carl Meyer, 9 years ago) (diff)

how to push single rev

Mercurial Branches

This page documents how to use Mercurial, rather than Subversion, to hack on Django. See also DjangoBranches.

Core developers

For people who are core committers, and want to use Mercurial rather than Subversion as their client:

  1. Install the hgsubversion extension (and understand basically how it works).
  2. Clone the Subversion repository (do this using hg version 1.5 or higher, or else the changeset hashes generated by hgsubversion will be incompatible with those from repos generated using newer hg versions, including the official Django hg mirror).:
    hg clone svn+ django
    This will take a Good While (lots of hours), and in some cases can take a Very Long Time for just one changeset (I gave up on r11505).
    1. Clone the official Django hg mirror in the normal way, using hg 1.5 or greater.
    2. Edit .hg/hgrc to say:
      default = svn+
    3. Do hg svn rebuildmeta. This works because the official Django mirror was been created by hgsubversion, and is updated only by hgsubversion.
  1. Use normal hg commands to make commits, switch branches, push back to the subversion repository etc. Remember to use hg rebase --svn, and not hg merge.


  • Use the bookmarks extension for git-style local feature branches, or named branches for feature branches that you need other people to see.
  • Alternatively, use the queues extension to manage long lived patches.
  • To collapse several commits into a single commit before pushing back to svn, use the histedit extension
  • To backport a changeset from trunk, use the transplant extension. Or use this handy script which will generate the commit message for you:
    function usage {
        echo "Usage: hg_backport <branch> <hgrevision>";
    if [ $# -ne 2 ]
            exit 1;
    BRANCH="releases/$SHORTBRANCH" # we only backport to release branches.
    hg st -a -r -m | grep '' > /dev/null && { echo "Working directory not clean - exiting" > /dev/stderr; exit 1; }
    SVNREV=`hg svn info -r $HGREV | egrep '^Revision' | cut -f 2 -d ' '`
    if [ "x$SVNREV" = "x" ]
            echo "Can't find svn rev";
            exit 1;
    echo "Backporting Subversion revision $SVNREV"
    hg update $BRANCH || exit 1;
    # Make a commit message first in case the transplant fails.
    hg log -r -1 --template "[$SHORTBRANCH] {desc}\n\nBackport of [$SVNREV] from trunk\n" > hg-commit-message.txt || exit 1
    hg transplant $HGREV || exit 1;
    # Modify the commit message
    hg rollback > /dev/null || exit 1
    hg commit -l hg-commit-message.txt || exit 1
    echo "Backport committed."
    The command line is like:
    hg_backport 1.2.X 13643
    where 1.2.X is a directory under 'releases/' in the Subversion repo, and 13643 is a hg revision ID. The change is already committed to the local repo, but not 'pushed', so you can still rollback if changes need to be made.


If you make two commits, and only want to push the first, you will have some trouble, since the hg push command doesn't support specifying revisions. Nice solutions to this welcome! - use hg push -r rev ?

Back to Top