Mercurial Now Has commit --amend

Mercurial 2.2.1 is out, and, among other new features and improvements, the commit command now has a --amend option. Git has had this for a while. Before 2.2 you could get the same functionality in Mercurial by using the mq extension, but it took at least 3 commands (qimport, qrefresh, qfinish). It's nice that you can do it with just one command now. Mercurial's relatively new phases come into play with --amend in that, by default, they will prevent you from amending a commit that has been pushed to or pulled from a remote repository. It's a nice little safety net to have, and of course you can override that behavior if you need.

It's nice to see this incredibly capable and easy-to-use tool get even better.

Comments

Vernon Mauery said…
It sounds like you will soon be able to just put an "alias hg='git'" in your .bashrc and be good to go. Ahhh, just join the dark side and leave your safety nets behind. :)
Ryan said…
I thought Mercurial's equivalent to Git's amend feature was to use rollback followed by commit.
Bryan said…
Ryan, that is another way you could amend a commit in mercurial, but it has caveats. rollback rolls back the last transaction, so if the last command that you did was commit, rollback followed by commit will work fine. If you have done a commit, and then some other command like, say, a pull, rollback won't put the commit back in your working copy, it will undo the pull. I'm pretty sure rollback won't save the commit message when it rolls back a commit, so if you want to just edit the commit message it's not going to be much help there either.
Anonymous said…
Well if you had pulled since the commit you wanted to amend, then you also couldn't use git commit --amend. You would need to rebase instead. AFAIK (that's how I do it, at any rate).
Bryan said…
hg pull doesn't do a merge like git pull does. From what I understand it's more like git fetch. You can still hg commit --amend after an hg pull, as I assume you could after a git fetch.
Anonymous said…
Yes indeed; a bad assumption on my part, that.

Popular posts from this blog

SystemVerilog Fork Disable "Gotchas"

'git revert' Is Not Equivalent To 'svn revert'

Git Rebase Explained