Mercurial extensions/en

De Goffiwiki
Aller à : navigation, rechercher

Mercurial extensions


Remove a revision without modifying the working directory

To cancel a commit that has just been done, you can do:

hg rollback

Or you can also, at any time, use mq, hg diff and patch to delete the revision X. Y being the revision X+1:

hg qimport -r Y:            # import all successors to mq
hg qpop -a                  # unapply all the successors
hg diff -c X > /tmp/X.diff  # output the changes of revision X to a file 
hg strip -r X               # delete X and all successors (there is none because they are saved as unapplied patches)
hg gpush -a                 # re-apply all the patches 
hg qfinish -a               # restore the patches as normal changesets
patch -p1 < /tmp/X.diff     # reimport the changes from formal revision X to the working directory

Update a revision

You want to update a revision that has been committed some time ago and already has successors.

hg qimport -r X:            # import revision X and all its successors to mq
hg qgoto X                  # unapply all the successors and leave X applied at the top of the stack
hg qrefresh -X "*"          # send back the changes of all files from X to the working directory 

# here you fix whatever problem was in revision X, the successors of X being still unapplied...
hg qrefresh                 # import all the changes from working directory to patch X
hg qpush -a                 # re-apply all the patches
hg qfinish -a               # finish all patches

Reorder patches

You have three patches X, Y, Z and you want to reorder them to Z, Y, X. This would work well if the patches are not inder-dependent, otherwise you better be careful and you will have to resolve conflicts.

hg qpop -a  #
hg qpush --move Z
hg qpush --move Y
hg qpush --move X

Merge two revisions

You want to merge revisions X and its successor Y:

hg qimport -r X:  # import X and its successors to mq
hg qgoto X        # unapply all successors of X
hg qfold Y -e     # merge Y over X and edit the commit message
hg qpush -a       # apply all patches
hg qfinish -a     # finish all patches

Import a file containing several changesets

You want to import to mq a file that has been created with:

hg export -r X:Z > /tmp/X-Z.diff  # export to /tmp/X-Z.diff the revisions X to Z 

mq itself doesn't allow to do it, as it will import the whole file as a single patch, resulting to an invalid patch. You have to do it in 2 steps:

hg import /tmp/X-Z.diff  # import the changesets as normal revisions
hg qimport -r X:Z        # import the revisions to mq


You probably want to activate this extension in order to get a colorful display, especially useful for hg diff.


This extension allows you to select file per file and line per line, which changes from the working directory you want to commit.


This extension is especially usefull to merge branches after you updated your repository. Imagine you have some local changesets X, Y, Z when you do:

hg pull -u

And this brings you some new public changesets A, B, C in a new branch. Your local branch and the one have a common ancestor revision O. To move X, Y, Z so that they will be successors or C, you can do:

hg rebase -b Z -d C  # move X (the oldest revision in the branch of Z after the common ancestor) and all its successors (Y and Z) upon C