If the commit in question is already pushed to another repository (Mercurial will track this using the commit phase), then I would simply make a new commit as a child of D
. There is no real advantage of creating the bugfix as a child of B
with a subsequent merge — noting in the commit message of E
that this fixes a bug introduced in B
works just as well.
If the commit that introduces the bug is still local (in the draft
phase with Mercurial), then you should simply edit the commit before pushing it anywhere.
With Mercurial you use the included histedit extension for this:
$ hg histedit B
An editor opens to let you specify what you want done for each commit. Change pick
to edit
in the line corresponding to B
. When you save the file and close the editor, the history editing begins. You can now fix the bug and run
$ hg histedit --continue
when you're happy with the result.
In Git you use a so-called interactive rebase for editing history:
$ git rebase -i B^
This starts the same process as for Mercurial. Change pick
to edit
and close the editor. Edit the files to your liking and amend the commit before continuing the history editing:
$ git commit -a --amend
$ git rebase --continue