Kirsten
Kirsten

Reputation: 18066

Source tree commit attempt fails with cannot amend public changesets error

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.

Upvotes: 2

Views: 1097

Answers (2)

OzAnt
OzAnt

Reputation: 52

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 :)

Upvotes: 2

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391336

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.

Upvotes: 3

Related Questions