You want the hg rollback
command. This command will remove the last transaction from your repository. A commit is a transaction, so you can use this as
% hg commit -m 'My elaburate bugfix.' foo.c foo.h
% hg rollback
% hg commit -m 'My elaborate bugfix.' foo.c foo.h
After the rollback the files will again be seen as modified, and this means that the second commit will store the same changes as the first, but with a better commit message.
Beware: hg rollback
is more powerful than a simple "uncommit" function. If someone has pushed to your repository, then that change will be the last transaction, and so hg rolllback
will remove their changesets. This means that you should only use hg rollback
on private repositories where you are sure that nobody else will have created transactions in the mean time.
Also, if you have not given the commit message on the command line, then you cannot just press up-arrow twice to redo the commit after a rollback. However, Mercurial 1.5 and later will save your last commit message in .hg/last-message.txt
so that you can always find it again after a rollback.