17

I'd like to amend my last commit, but running

hg commit --amend

gives me

abort: cannot amend public changesets

even though I know that it's safe to edit the changeset. How can I change the phase of my last commit and/or tell Mercurial that it's safe to amend?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238

1 Answers1

35

On the Mercurial wiki, there's a good overview of phases.

To convert the current commit from "public" to "draft" commit in order to allow amending, use

hg phase --draft --force .

(or replace . with another revision if you want to edit a different changeset).

Carlo
  • 2,103
  • 21
  • 29
Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
  • Pushing it upstream still results in a history of two commits, and local 'hg log' confirms two commits as well - is there any way around this? So it only shows the amended commit ? – Daniel Sokolowski Aug 28 '13 at 00:38
  • 4
    No, if you've pushed the changeset then you shouldn't amend it, which is why hg prevents you from doing so. (In some cases, you know that it's only been pushed to another private repo of yours, in which case this answer is useful.) – Sophie Alpert Aug 28 '13 at 07:05
  • 1
    @Daniel Sokolowski, you could have removed the push of the first commit using undo/roll back on the upstream repo. But you need to be quick, and do this before any further change sets are pushed to it. – Steve Pitchers Jun 10 '14 at 11:19