2

So that I could learn source tree, I set up a private repository in bitbucket and made 2 clones to my computer. When I try to commit from one of the clones I get the following error.

hg commit -y --amend --logfile C:\Users\kirsten\AppData\Local\Temp\n1j0esve.5ce abort: cannot amend public changesets

Completed with errors, see above.

Kirsten
  • 15,730
  • 41
  • 179
  • 318

2 Answers2

3

The error message tells you everything you need to know, provided you know what it means.

A "public" changeset is one that you've either pulled from another repository, or pushed to another repository (or forcibly switched to the public phase but that's not a typical reason).

Basically, is it available/shared for anyone else? Then it is public.

The "--amend" parameter to the commit command is specifically used to edit the previous changeset, in order to avoid another changeset on top of it.

Typical usecases for the "--amend" parameter are:

  • Forgetting to remove a password or debug code before committing
  • Forgetting to save a file in your editor, so that the changes you've made in it weren't on disk and thus not included in the changeset.

However, you cannot amend a public changeset, because this is most likely not what you want to do. You can do it by forcing the changeset in question to enter the draft phase, but since you really don't want to do that either I'm not going to post the command for that here.

The problem, if you were to amend a public changeset, is that it rewrites the changeset, locally. The changeset still exists "out there" (in the public) as the old version, without your amended change. So the next time you pull you will get the original changeset.

Example history before amend (all changesets are public):

A---B---C---D

Then you decide you want to amend the D changeset, getting d:

A---B---C---d

The next time you pull you get this:

           D
          /
         /
A---B---C
         \
          \
           d

Now you have both the original and the amended changeset. If instead of pulling you tried to pull you would get the error message stating you're trying to create another head in the remote repository.

None of this is what you want to do because you should not amend a public changeset. Which is what the error message told you.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • Thank you Lasse. I am a SourceTree and DVCS newbie. When you say A "public" changeset is one that you've either pulled from another repository, or pushed to another repository (or forcibly switched to the public phase but that's not a typical reason)." I am a bit confused. There is only one remote repository... so how can I have pulled from or pushed to the wrong one? – Kirsten Feb 03 '15 at 08:39
  • The important part is that if you've pulled a changeset from *somewhere*, or pushed it *somewhere*, it is public. It does not matter where that somewhere is, who owns it, whether it is on a remote server or in another directory on your own disk, etc. Push/pull makes changesets public. – Lasse V. Karlsen Feb 03 '15 at 11:14
  • Oh dear, this is going to sound silly but I don't know how to "amend a change set" What could I have done to amend the change set? Also I am confused by your statement "If instead of pulling you tried to pull you would get the error message stating you're trying to create another head in the remote repository." I thought pulling was getting things from the remote repository, so why would it be trying to write things to it? – Kirsten Feb 03 '15 at 20:04
  • You added the `--amend` parameter. – Lasse V. Karlsen Feb 03 '15 at 20:04
  • i must have done something http://stackoverflow.com/questions/17604232/edit-a-commit-message-in-sourcetree-windows-already-pushed-to-remote – Kirsten Feb 03 '15 at 20:47
2

This answers the question in the comments of the accepted answer: "how could i have done that in Sourcetree ?"

I think you commit with the option "Amend latest commit" enter image description here

which is a bit hidden :)

OzAnt
  • 52
  • 2