Delete multiple heads - mercurial

C:\Users\Itu\workspace\Compiler>hg branches
default 13:aa6af82c5458
C:\Users\Itu\workspace\Compiler>hg heads
changeset: 13:aa6af82c5458
tag: tip
user: Itun
date: Sun Sep 18 22:27:06 2011 +0400
summary: Update 1.0.0.2
changeset: 9:d36e5ac454b1
parent: -1:000000000000
user: Itu
date: Sun Sep 18 06:50:25 2011 +0400
summary: New PR
changeset: 8:758cd394d82a
user: Itun
date: Sun Sep 18 06:48:17 2011 +0400
summary: asdasd
changeset: 4:c4c981b4ff43
user: Itun
date: Sun Sep 18 03:31:58 2011 +0400
summary: Update
C:\Users\Itu\workspace\Compiler>hg merge
abort: branch 'default' has 4 heads - please merge with an explicit rev
(run 'hg heads .' to see heads)
How you can see I have the one branch and 4 heads.
When I try to pull in my eclipse mercurial plugin, it returns me message about multiple heads and offers me to rebase or merge. Then I did not understand anything and closed it.
I think I need something to delete this heads. It would be great if somebody could explain me this and show how to do this in the eclipse plugin, but other help is appreciated.

The safest way to remove the extra heads is to make a new clone, grabbing just the head you want with -r:
cd C:\Users\Itu\workspace
mv Compiler Compiler-backup
hg clone -r aa6af82c5458 Compiler-backup Compiler
This will move just aa6af82c5458 and its ancestors to the new clone, leaving the old heads in Compiler-backup. You can always hg pull them over later, or just delete the backup (losing your data).

Mercurial has an entire wiki page devoted to the topic of multiple heads.
I highly suggest reading it before proceeding on your apparent course of action.
The folks at Fog Creek have provided some friendlier material.
You might consider working with them, since it sounds like you might need some support.

Related

Generating merge logs with mercurial

We're using Mercurial for source control and would like to introduce automatic merging and changelog for our QA process.
For the purpose of this discussion, let's just assume that we use a simple 3-branch flow like the below:
\ = forward merge
| = back merge of fix
Default --O--A--*--B--*---
\ ^ \
\ | \
QA -----M--X--C--*--N---
^ \
| \
Master --------H--------*---
So the question is:
Is it possible to construct a revset query that, at merge N, preferably before but otherwise after actually performing it, will result in a log of all commits on Default branch, which aren't yet in QA branch (On the above drawing that would be A and B).
Alternatively formulation:
Is it possible to construct a revset query that will return all the changesets, which would get merged if we merged Default into QA.
I'm only interested in commits on Default branch, not individual commits in feature branches already merged into Default (Feature branches not included on the drawing). I am also not interested in commits on the QA branch.
The repository is pretty well maintained, but a couple of years old and contains about 13000 nodes.
I've been experimenting with ancestor and ancestors, but either I get X as the latest common ancestor, or some very very old node. I understand the logic of getting X, but I'm really after O.
The most luck I've had is with variations of this:
hg log --rev "((heads(branch('Default')) and !closed()) % heads(branch('QA'))) and branch('Default') and p2(!branch('QA'))"
hg log --rev "((heads(branch('Default')) and !closed()) % heads(branch('QA'))) and branch('Default') and !children(branch('QA'))"
Update
Using "hg merge --preview --rev XYZ", as suggested by Tom, generates output like this:
changeset: 13070:7e59fc16aa4e
branch: Default
parent: 13068:5b9409ad504f
parent: 13069:849bd43d2023
user: *******
date: Mon Dec 18 18:40:46 2017 +0200
summary: Merged Feature branch A
changeset: 13071:07470ff919ff
branch: Feature branch B
parent: 13061:540eda2c959b
parent: 13068:5b9409ad504f
user: *****
date: Mon Dec 18 18:49:42 2017 +0200
summary: Merge with Default
changeset: 13072:a53260ffabca
branch: Feature branch B
user: *****
date: Mon Dec 18 18:58:05 2017 +0200
summary: Some text
changeset: 13073:37c895f2abf0
branch: Default
parent: 13070:7e59fc16aa4e
parent: 13072:a53260ffabca
user: *******
date: Mon Dec 18 18:58:05 2017 +0200
summary: Merged Feature branch B
Not too bad, but not super fun either. At least it requires more logic than simple grep/sls to parse.
Thanks in advance,
John
I found a solution that mostly does what I want:
hg log --rev "branch('Default') & !ancestors(branch('QA')) & ancestors(heads(branch('Default')) & !closed()) & !children(branch('QA'))"
The only thing now missing is to exclude multiple head merges, since they're just noise in a changelog.
Update:
So I picked this project up again and found some great answers elsewhere on SO.
The following produces output similar to hg merge --preview, but can be templated:
hg log -r "ancestors('$sourceBranch') - ancestors(.)" --template $template
This filters out all commits not on source branch:
hg log -r "(ancestors('$sourceBranch') - ancestors(.)) and (branch('$sourceBranch'))" --template $template

Why does MacHg tell me it's pushing hundreds of thousands of changesets when my project only had a few revisions?

Can anybody explain to me what's going on here? Are there two kinds of 'changesets' in Hg?
I have a big project with a lot of big files, and it was getting sluggish, so I deleted the .Hg folder and started over with a new repo in bitbucket. Or so I thought.
This particular Push should only have 200K or so of added/changed files, so not only do I not know why it's reporting so many changesets being pushed but I also don't know why it's taking so long. (At this rate it'll take an hour.)
When it finally did finish, it said it had pushed 2 changesets in the dialog.
Here's hg log, fwiw:
changeset: 3:e21eca3496ea
tag: tip
user: Jamie Fristrom <***#gmail.com>
date: Fri Nov 23 12:58:21 2012 -0800
summary: Project settings, fixed duplicate buildings, reshadow
changeset: 2:9ecb5aab03c2
user: Jamie Fristrom <***#gmail.com>
date: Thu Nov 22 21:59:09 2012 -0800
summary: Fresh new repo
changeset: 1:5b95e18a6377
user: Jamie Fristrom <***#gmail.com>
date: Tue Nov 20 17:20:02 2012 -0800
summary: Fresh new repo
changeset: 0:e2ad59f1136e
user: Jamie Fristrom <***#gmail.com>
date: Tue Nov 20 17:03:36 2012 -0800
summary: initialize repository
Could this have something to do with the way BitBucket works? I have a bunch of repos in BitBucket.

How to push, without creating new heads, after creating multi-head branch, rebase and several merges

I did a series of dumb steps with my local copy of our shared repository, and I'm looking for a way how to fix it. The steps are:
I used bookmarks to have multiple heads of a development branch, that other people use:
-o---o---o-----o--- <- dev branch
\----1----1------ <- another head of the dev branch,
where I committed stuff
I created a new branch, still local, some time later
/---------------x <- new branch
-o---o---o-----o--- <- dev branch
\----1----1------ <- another head of the dev branch,
where I committed stuff
for one head, that contains only my code, I did a rebase on another branch
/-1'--1'-- <- rebase
/---------------x <- new branch
-o---o---o-----o--- <- dev branch
\----1----1------ <- another head of the dev branch,
where I committed stuff
then, I merged the rebase, and then, a couple of commits later, I merged default
----------d-\ <-default
\
/-1'--1'\ \
/---------------x--------x--x-x-x-- <- new branch
-o---o---o-----o---
\----1----1------
Now, I wanted to push my new branch to the server (hg push --new-branch -b newBranch), but I get abort: push creates new remote head, since commits 1' belong to dev branch.
What is the right thing to do? I would like to avoid creating this additional head.
Update:
Per request, this is the output of hg heads:
changeset: 839:f2033d695fcd <- want to push this
branch: newBranch
tag: tip
user: me
date: Wed Oct 31 13:05:51 2012 +0100
changeset: 826:7fde19d7f467
branch: devBranch
user: my-collegue
date: Tue Oct 23 14:59:42 2012 +0200
changeset: 820:23853bbf68df <- the part after rebase that got merged
branch: devBranch
user: me
date: Mon Oct 22 15:36:26 2012 +0200
changeset: 807:899344cfb145 <- obsolete (branch with 1's)
branch: devBranch
parent: 711:454f29c03fb1
user: me
date: Mon Oct 22 15:36:26 2012 +0200
changeset: 712:d5e8a62a7f5f <- default, needs to stay
parent: 648:2bbcc01aa191
user: me
date: Wed Aug 22 16:21:09 2012 +0200
You can push only the one head you're interested in mercurial. For you that would mean doing:
hg push -r f2033d695fcd
If the destination repo has been updated you need to pull, merge, and re-push:
hg pull
hg up -r <remote head>
hg merge -r f2033d695fcd
hg ci
hg push
I solved the problem, without pushing another head to the repo, and without merging 23853bbf68df onto newBranch. This is probably not the cleanest way to do it, but I will leave it as a reference. In a nutshell, I reconstructed the whole branch by taking all commits and re-applying them.
First, I killed the newBranch'es head 899344cfb145, by using strip on the first diverging revision I did:
hg strip -r 646
Then, I produced email patches (couldn't play with mq) for all commits that are in newBranch, since it's inception:
hg export -g -r 797:808 -r 810 -r 815:822 -r 824:830 -o "%n-%m.patch"
797:808 are the patches in newBranch that were in the rebased part of devBranch (1' commits from the original figure).
810 and 815:822 are other patchs in newBranch. 811:814 belong to a different branch, so I had to exclude those.
823 is a merge commit with default, so I skipped this one.
824:830 are all the commits after the merge with default.
Now, I imported these patches on a new head of newBranch:
hg up -r 796
# there are 29 patches, applying till merge
hg import --bypass {01..21}*.patch
hg up tip
hg merge default
hg ci -m 'merging in default'
hg import --bypass {22..28}*.patch
Finally, I just stripped of the original head of newBranch.
hg strip -r 797
This may not work in every situation. During the merge, I had to resolve some conflicts, too, but pretty benign. Hope this helps someone.

How can I list a series of revisions using 'hg log'?

I'm attempting to use the hg log command to show a series of revisions, x through y.
When I do this:
hg log -r 1+5
I get this:
changeset: 1:7320d2a9baa5
user: Tim Post <tpost#whereiwork.com>
date: Fri Sep 30 20:38:29 2011 +0800
summary: Foo foo everywhere is foo
changeset: 5:8d6bea76ce60
user: Tim Post <tpost#whereiwork.com>
date: Fri Sep 30 20:51:42 2011 +0800
summary: Blah blah blah
Which is Mercurial understanding that I want to see revisions one and five instead of one through five.
Oddly enough, this works:
hg log -r 1+2+3+4+5
But, that gets extremely cumbersome, especially when trying to get a summary between revisions that are +500 away from each other.
Is there a way to get logs for revisions x through y instead of x and y without concatenating every revision in the series?
I'm using the output in order to determine how many commitments each developer made in a given series. If I simply can't do that using the hg command, I'm more than open to using the Mercurial API. I resorted to the hg command because I did not see an obvious way of doing it via the API.
By API, I mean just using Python via a hook or extension.
hg log -r1:5.
Mercurial has an entire mini-language devoted to selecting revisions for commands (not just for logs). For more information, see hg help revsets (needs Mercurial 1.6+).

Problem of hg clone src#tag dest

I have a repository named master which keeps product releases. It has several tags (such as 1.0,2.0,3.0) as baseline. When I want to create hot fix for one version, for example 1.0. I use command as following:
hg clone master#1.0 hotfix_1.0.1
cd hotfix_1.0.1
hg tip
changeset: 14:b2492c2611a1
tag: tip
user: codingboy <codingboy#gmail.com>
date: Thu Dec 09 14:03:23 2010 +0800
summary: fix bug4
I find tip version is what I need, but is not tagged with 1.0. It will cause my changes in hotfix_1.0.1 can not be push to master. the error is
(abort) unknown 1.0 revision.
I check master repository. the log shows below
changeset: 15:3497c46cbc7f
tag: tip
user: codingboy <codingboy#gmail.com>
date: Thu Dec 09 14:03:27 2010 +0800
summary: Added tag 1.0 for changeset b2492c2611a1
changeset: 14:b2492c2611a1
tag: 1.0
user: codingboy <codingboy#gmail.com>
date: Thu Dec 09 14:03:23 2010 +0800
summary: fix bug4
so it seems cloned repository lost changset#15. My understanding is hg clone src#tag dest should clone tag which I need. But this operation can not clone child of changeset#14 which is do tagging. So what I have done is to use command
hg clone master hotfix_1.0.1 -u 1.0
I do not like this command. if master repository is huge and I just want to fix old version, It will waste time to clone and push changes.
Do I have any other approach to clone one repository from one baseline or tag correctly?
thanks...
Due to the design of Mercurial tags, the tagged revision does not contain that tag. In other words, 1.0 doesn't "know" it's 1.0.
Mercurial recommends the solution you give at the end. A possible mitigation for the performance issues is to keep (pulling as needed) a single clone of master that you don't modify. Then, (as needed) clone that locally and update to the desired version. The clone will (assuming same volume and a modern filesystem) use hard links, minimizing the required copying.