1
votes

Another git user confused by Mercurial branches here. I've done something that I can't figure out how to undo and as a result I cannot push my totally unrelated changes. Any help would be appreciated.

Here's the story, I think:

  • I started working on something on default. I realized this was a mistake as it would become a PR, so the next commit I did on a branch feature1. I then submitted a PR on bitbucket.

  • I started working on something else, also off of default, this time I was certain to use a branch feature2, and I did purposely "hg up -r ..." with the revision number before my feature1 commit so as not to include that change.

At this point the history looks something like,

                   -- G (default) - H (feature1)
                  /
.. D - F (default)
                  \
                   -- I - J - K (feature2)
  • My PR was not accepted, so I close feature1.

  • There has been development on default in the parent repository, so I hg pull. Now it looks something like,

                       -- G (default) - H (feature1) [my repository, closed]
                      /
    .. D - F (default)--- L (default) [parent repository]
                      \
                       -- I - J - K (feature2) [my repository]
    

.. plus lots of changes on other branches that I don't know anything about.

  • But I'm happy with feature2 and I want to make a PR for it, so I try to hg push --new-branch, but I get the message,

    abort: push creates new remote head 7a341084eb8a!

Ok, so use hg glog and it appears the checksum corresponds with the parent work, i.e. L in the diagram above. Mercurial seems to be complaining that I have a commit on a closed branch with the branch default that has not been merged into default! But I don't want it to exist anymore! However, I don't want to strip it as then it would make reading the old, closed PR impossible.

If I try to push just my own branch, hg push --new-branch -b feature2, then I get:

abort: push creates new remote head 062efd5d0886!

i.e., same problem but with a different head. This one appears to correspond with the first patch of feature2! That is, I in my diagram.

This makes no sense.. a closed branch is stopping me from pushing the changes on an entirely other branch. Meanwhile I can't figure out what multiple heads it's even talking about when pushing my feature2 branch, since there is really only one feature2. The recommendation is to "merge" before pushing, but I can't even figure out here what to merge. I don't want to merge my rejected change on default, and when I do hg merge default on feature2, thinking maybe I need to take into account the latest upstream changes, this merges G, from my closed branch instead of the upstream head.

So, clearly, I just don't understand Mercurial branches. In git I would just delete the feature1 branch and that would be that. How do I resolve this?

1

1 Answers

1
votes

But I'm happy with feature2 and I want to make a PR for it, so I try to hg push --new-branch, but I get the message,

abort: push creates new remote head 7a341084eb8a!

At this point, revision L is the head of branch default, and you are trying to send revision G. Revision G is in the default branch, so you will create another head. The branch feature1 was closed, but not the default branch in the revision G. You can update to revision G, and close the branch there, or merge it with revision L.

If I try to push just my own branch, hg push --new-branch -b feature2, then I get:

abort: push creates new remote head 062efd5d0886!

If revision I is in the default branch, you have the same problem as above.

If not, try hg push -r <rev number of revision I>.