I'm looking for a counter-part of git commit --amend
in Mercurial, i.e. a way to modify the commit which my working copy is linked to. I'm only interested in the last commit, not an arbitrary earlier commit.
The requirements for this amend-procedure are:
if possible, it should not require any extensions. It must not require non-default extensions, i.e. extensions which do not come with an official Mercurial installation.
if the commit to amend is one head of my current branch, no new head should be created. If the commit is not head, a new head may be created.
the procedure should be safe in a way that if for whatever reasons the amending fails, I want to have the same working copy and repository state restored as before the amending. With other words, if the amending itself can fail, there should be a fail-safe procedure to restore the working copy and repository state. I'm referring to "failures" which lie in the nature of the amend-procedure (like e.g. conflicts), not to file-system-related problems (like access restrictions, not being able to lock a file for writing, ...)
Update (1):
- the procedure must be automatable, so it can be performed by a GUI client without any user interaction required.
Update (2):
- files in the working directory must not be touched (there may be file system locks on certain modified files). This especially means, that a possible approach may at no point require a clean working directory.
You can now use the
--amend
option withhg commit
to update the last commit with the current working directory, since the release of Mercurial 2.2.From the command line reference:
The great thing is that this mechanism is "safe", because it relies on the "Phases" feature to prevent updates that would change history that's already been made available outside of the local repository.