Search code examples
mercurialdvcsmercurial-hookmercurial-extension

Amending the local commit after rebase in mercurial


In the beginning, my local repo looked like:
C1 -> C2 -> My1
and the remote repository looked like:
C1 -> C2 -> R1 -> R2
So I did:
$ hg pull
$ hg rebase
Now the repo looks like:
C1 -> C2 -> R1 -> R2 -> My1

Now I have made some changes to a file "File1.java" and want these changes to be a part of the last commit My1. When I do a:
$ hg commit File1.java --amend
the error message I get is:
abort: cannot amend merge changesets
On googling I found this, according to which it looks like an issue in mercurial but I am sure there is a way around it.
Please tell me the set of steps to amend the new changes in the last local commit.


Solution

  • It look like My1 is a merge but your diagram does not highlight that at all. Can you check the state of your repo with:

    hg log --graph
    

    If My1 is a merge (and you expected it to be merge). Mercurial 2.6 should be able to edit a merge changeset. So if you upgrade to Mercurial 2.6.1 or above your original command will work.

       hg commit --amend  File1.java