Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial merge branches? (abort: push creates new remote branches)

Tags:

mercurial

I'm new to Mercurial, and I made the mistake of making different changes on different systems before the main repository was up to date. (I understand this is what Mercurial is built for, but my thick brain is struggling to resolve the issue.)

Now on my primary development server, everything is up to date and committed. However...

$ hg push
abort: push creates new remote branches: 4f2672f039d7!
(use 'hg push --new-branch' to create new remote branches)

I don't really want a new branch. I just want all the changes to be merged.

$ hg heads
changeset:   459:ff5f94e44aba
branch:      4f2672f039d7
tag:         tip
parent:      458:e63d02baf4cf
parent:      455:267abda62069
user:        mike@...
date:        Tue Sep 13 14:25:16 2011 -0400
summary:     Images from prof

changeset:   455:267abda62069
parent:      453:a74757e26357
user:        [email protected]
date:        Tue Sep 13 09:08:12 2011 -0400
summary:     images for FLC

Point me in the right direction?

EDIT: (adding detail)

When I try to merge, I get the following result:

$ hg merge
abort: branch '4f2672f039d7' has one head - please merge with an explicit rev
(run 'hg heads' to see all heads)

I have tried hg merge ff5f94e44aba, and all of the revs listed above, and each one returns the same result:

$ hg merge 267abda62069
abort: merging with a working directory ancestor has no effect
like image 743
Mike S. Avatar asked Sep 16 '11 17:09

Mike S.


2 Answers

It looks like you've accidentally created a branch with a silly name. What you most likely want to do is reapply your changes with a branch name that makes better sense. There's no totally automatic way of doing this, but you can extract each changeset as a patch, revert to the point where you messed up and reapply those changes on the proper branch.

Basically what you need to do is look at the changelog; probably by running hg out to see what's missing from the central repository. Make a note of each of the revs that you want to keep.

Next update to the last good revision. Make sure that you are on the branch you wanted your commits to be on.

Now you will apply each of the changes you made and commit each one. You can automate this process something like this:

BADREVS="123 124 125 126"

recommit() { hg di -c $1 | patch -p1;  hg ci -m "$(hg log -r $1 --template '{desc}')";}
for rev in $BADREVS; do
    recommit $rev
done

Now you've got your changes in your local repository twice; once as the commits on the weird branch and again on the right branch. You can push those changes to the central repo using hg push -b GOODBRANCH so that only the changes to the right branch go up; Alternatively, you can install the strip extension to remove the changes you didn't want from the local repo and then you can push as normal.

By the sound of it; you will still have to deal with the changes made to the central repository before you can push, since you pushed changes from another repo. You probably want to do this merging after you clean up the change history in the local repo.

like image 100
SingleNegationElimination Avatar answered Nov 15 '22 23:11

SingleNegationElimination


Pull from remote and then update / merge / commit first. Then you won't make new branches.

like image 43
cdeszaq Avatar answered Nov 16 '22 01:11

cdeszaq