9

Hi I hope you can from my i/o tell how to proceed to merge everything to the latest update without losing my changes:

$ hg merge
avbryter: grenen 'default' har 4 huvuden - sammanfoga med en specifik rev
(kör 'hg heads .' för att se huvuden)
ubuntu@ubuntu:/media/Lexar/montao$ hg heads
ändring:     192:e571b17295e9
märke:       tip
förälder:    175:f50d4c4461e5
användare:   tekniklas
datum:       Sat Jan 08 04:45:07 2011 +0000
kortfattat:  twitter support added

ändring:     191:9e419ce3e7e1
användare:   tekniklas
datum:       Wed Mar 09 12:56:27 2011 +0000
kortfattat:  adsense maps

ändring:     159:f8d974793b12
förälder:    157:ef1d955b9236
användare:   tekniklas
datum:       Sat Dec 18 17:05:45 2010 +0000
kortfattat:  remove

ändring:     89:008a2ac46b4f
användare:   tekniklas
datum:       Sun Aug 01 07:10:40 2010 +0000
kortfattat:  classifiedsmarket/market/market_ad_preview.html

ubuntu@ubuntu:/media/Lexar/montao$ 

The latest version is good and I want to "lose" the older heads.

UPDATE. After proceeding with the tip this is the latest output from hg heads:

    $ LC_ALL=C hg heads
changeset:   195:fa7d0ec3760d
tag:         tip
user:        tekniklas
date:        Fri Mar 11 06:04:17 2011 +0000
summary:     searchbox

changeset:   192:e571b17295e9
parent:      175:f50d4c4461e5
user:        tekniklas
date:        Sat Jan 08 04:45:07 2011 +0000
summary:     twitter support added

changeset:   159:f8d974793b12
parent:      157:ef1d955b9236
user:        tekniklas
date:        Sat Dec 18 17:05:45 2010 +0000
summary:     remove

changeset:   89:008a2ac46b4f
user:        tekniklas
date:        Sun Aug 01 07:10:40 2010 +0000
summary:     classifiedsmarket/market/market_ad_preview.html

EDIT, current issue status is:

$ LC_ALL=C hg heads
changeset:   195:fa7d0ec3760d
tag:         tip
user:        tekniklas
date:        Fri Mar 11 06:04:17 2011 +0000
summary:     searchbox

changeset:   192:e571b17295e9
parent:      175:f50d4c4461e5
user:        tekniklas
date:        Sat Jan 08 04:45:07 2011 +0000
summary:     twitter support added

changeset:   159:f8d974793b12
parent:      157:ef1d955b9236
user:        tekniklas
date:        Sat Dec 18 17:05:45 2010 +0000
summary:     remove

changeset:   89:008a2ac46b4f
user:        tekniklas
date:        Sun Aug 01 07:10:40 2010 +0000
summary:     classifiedsmarket/market/market_ad_preview.html

ubuntu@ubuntu:/media/Lexar/montao$ LC_ALL=C hg --config ui.merge=internal:local merge 195
abort: merging with a working directory ancestor has no effect
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424

4 Answers4

22

Mercurial is about building a permanent history of your work, so none of its normal usage modes include "getting rid" of old heads.

The most Mercurial-like way to do this is to merge that head in selecting nothing from it.

hg update tip
hg --config ui.merge=internal:local merge 191 # keep my files

Found here.
That will eliminate that head, selecting nothing from it.

Other options that actually remove it from history include just doing:

hg clone -r tip myrepo mynewrepo

Which gets you a new clone that has only your newest head and its ancestors (not its sibling heads) which you can replace your old repo with if you like the result.

That's generally inferior if you buy into the keep-everything-forever model (I do) and doesn't work at all if other people already have clones fo your repo.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • Kool! I tried and I get the info "merging with a working directory ancestor has no effect. The reason I want to remove old heads are that they are mistakes, I didn't learn yet to work with heads. – Niklas Rosencrantz Mar 10 '11 at 05:42
  • 1
    Getting rid of old heads is very much useful when you had no "forbid multiple heads" hook and then you try to add one: you have to first "clean" your repos otherwise nobody can work anymore.. :-). So, thanks for the pointer to this FAQ. BTW, it would be nice to be able to apply --close-branch even to unnamed ones. – Christophe Muller Mar 10 '11 at 06:28
  • 1
    Merging the heads back as I show in the first example gets you past your 'forbid multiple heads' hook -- that's what I'd be doing were I you. Close-branch, on the other hand will still leave it as a head (just a slightly hidden one) so it won't get past your hook. Do the merge. – Ry4an Brase Mar 10 '11 at 16:14
  • Thanks you for proceeding and informing. I try do the merge and get an interruption: $ hg --config ui.merge=internal:local merge 195 \n avbryter: merging with a working directory ancestor has no effect – Niklas Rosencrantz Mar 11 '11 at 06:28
  • 3
    If you're getting that message on a merge, then you're not merging a head with a (different) head. Two heads, by definition, can't have a ancestor/descendant relationship. Is it possible you're still updated to revision 195? You can check that with 'hg parents'. If so, then that command is merging 195 with 195, which doesn't do much. – Ry4an Brase Mar 11 '11 at 15:47
  • Thanks Ry4an. It seems you're entirely correct what's going on. I'll try accordingly merge different heads and I will report back to say how it worked. – Niklas Rosencrantz Mar 13 '11 at 05:27
  • Ry4an and Vadim, your solution is good, but your "other approach" of "hg clone -r tip myrepo mynewrepo" has real danger! It will not pull any other branches from myrepo to mynewrepo. The only correct way of doing that is to list all the heads and branches you *want* to bring in, then do the clone with the -r option, then go and do individual "pull" instructions for all the branches you want to keep. It's detailed work, but it's the only way of doing repo surgery that I know. – markgalassi Aug 24 '18 at 16:06
3

Nowadays you can close your branches (anonymous or not) with:

hg commit --close-branch -m "Closing branch."

You need to be in the branch you want to close before doing it.

I think that closing branches is better than merging it discarding changes because have a better meaning. When closing you said "This changes aren't useful any more", when merging you said "I like the changes but they are already included manually" (but maybe is what you wanted).

You can see this related question Mercurial: beheading a head or this one if you don't want/can't update Can you close a Mercurial branch without updating to it first?.

Community
  • 1
  • 1
PhoneixS
  • 10,574
  • 6
  • 57
  • 73
0

You can close your old branches. See article from official wiki.

shellholic
  • 5,974
  • 1
  • 20
  • 30
0

Try to merge with lastest remote head and then push your commit

hg merge
hg commit -m 'merge'
hg push
teodor
  • 85
  • 1
  • 7
  • Teodor, unless I'm mistaken this is very different from what the original poster wanted. Niklas wanted to discard a head, while your suggestion would merge it in. – markgalassi Aug 24 '18 at 15:54