I'm having the following problem: I commited two changesets into the default branch, but now I think I should put them into a new branch. That means I want to branch of from the revision before these changes happened, put those changesets into the newly created branch and erase them from the default branch's history.
What's the best way to do this in Mercurial?
hg rebase can probably do that.
Otherwise you can do it manually:
hg clone -r <previous rev> old new
cd new
hg branch <branchname>
hg export -R ../old <first cset> |hg import
hg export -R ../old <second cset> |hg import
Related
I have local branch and master branch. I use hg merge local branch with master branch, after that I find that master branch version is modified and I have to merge with new master branch.
I don't know how to back local branch status and merge new master branch.
If you committed the merge and then found that there were new changesets on master, you could do either of:
hg pull the new changesets, then hg merge again, then push the two merges.
hg strip your merge, then hg pull and hg merge <localbranch> again.
If you haven't committed first merge yet, you could hg update default -C to throw out the merge changes, then hg pull and hg merge <localbranch> again.
hg update develop --clean
remote: conq: repository does not exist.
abort: no suitable response from remote hg!
I would like to be able to switch to my develop branch, to undo my last 2 commits and merge the develop branch with tip or close it!
OR
just close and rename the branch, but since I can not update to it I don't know what to do.
I would like to: overwrite branch x with branch y:
hg update x
hg commit --close-branch -m 'closing branch x, will be overwriten with branch y'
hg update y
hg branch -f x
hg ci
but i can't update to x. How to fix/force this?
I used the MQ extension:
hg qinit
hg qimport -r 4:tip
hg qpop -a
hg qdelete 4.diff
hg qpush -a
hg qfinish -a
That worked but after a pull the removed stuff was back in..
But, I just created a new Branch one from tip using -f with the same name.
that works good enough for me. Can't remove the 'wrong' branch it since it is 'out of the bottle' published.
If there are two branches, and I have been doing work on the default branch, I think one way to push to the foo branch of the other clone is
cd ~/development/clone2
hg up default
hg pull ~/developmet/clone1
hg up foo
hg merge default
or
cd ~/development/clone1
hg up default
hg push ~/developmet/clone2
cd ~/development/clone2
hg up foo
hg merge default
These 2 methods work exactly the same? (one is a pull, one is a push).
Is there an easier way to directly push clone1's default branch to clone2's foo branch? thanks.
(I use clone 1 to see all the changes I have done (without seeing anybody else's changes), and use clone2 to merge and integrate with other team members)
You can always push and pull a single revision and all of it ancestors using:
hg push -r revision ~/development/clone1
or
hg pull -r revision ~/development/clone2
There's no way to "push to another branch" because you'll always have to merge the two different branches manually
Both methods you described work exactly the same, but the first one is recommended (Always do the merge work in your clone, not the integration repository or somebody else's clone)
Maybe is an intentional omission but in both examples you have to commit the result of the merge and in the first example you have to push the merge changeset back to clone2
So in ~/development/clone1 do:
hg up default
hg pull -u ~/development/clone2
hg up foo
hg merge default
hg ci -m 'merged default into foo'
hg push ~/development/clone2
If you do this a lot you may consider adding this lines to your ~/development/clone1/.hg/hgrc file
[paths]
default = ~/development/clone2
This way you can omit the repository path when you're pulling and pushing from the integration repository
I'm trying to move changes from a couple of changesets into one changeset on the other branch. There are other changes in between that I want to skip, so I don't want to simply merge everything.
hg transplant moves the changes correctly, but now I'd like to flatten them into a single commit. How can I do that?
You can fold them by
Backup the repository, a failure during the process can destroy data
transplant the desired changes to the target branch
transform them there into a mercurial queue (hg qimport -r first-to-fold-rev:)
fold them into one patch (hg qpop until the first patch is applied, then hg qfold <<patch name>> the following patches into this one)
Edit the commit message (When there are NO OUTSTANDING CHANGES hg qrefresh -e)
apply the single patch to your repository (hg qfinish -a).
When there are further unfolded patches:
hg qpush until the head patch
hg qfinish -a
Review the new repo state (hg glog/hg incoming)
hg rebase has an '--collapse` option. I think this is what you are looking for.
I am trying to clean up some cloned repositories I have, basically converting clones into named branches.
What's the easiest way to do this?
The only way you can make them named branches would be to rewrite their history, because the name of the branch is part of the history. However, if you can survive without having the branches be named in the past (the future is fine) then you can just pull all the repos into the main one (without merging!) and then label your branches once they're in.
For example, if you have MainRepo, Feature1Repo, and Feature2Repo, you would do the following:
$ cd MainRepo
$ hg pull ../Feature1Repo
$ hg pull ../Feature2Repo
Now, if you look at the DAG in something like TortoiseHg, you'll see a couple different heads. From here, you just hg up and hg branch:
$ hg up feature1headrev
$ hg branch Feature1
$ hg up feature2headrev
$ hg branch Feature2
From here forward, you'll have your named branches.
Note: If the hg pull complains about the repositories not being related, you can do an hg pull -f, which will create multiple tails in the repository. This is usually not how true branches are, but it is sometimes useful.
You could use hg export to create a bundle of changes, and then hg import them to your new branches.
Let's say you have a common base, revA, and then two clones which each diverge from revA into revB and revC.
In the first clone: hg export -r revA -r revB > revB.patch
In the second clone: hg export -r revA -r revC > revC.patch
Now you have two patches containing all the changes made in the clones.
In the original repository:
hg up revA
hg branch branchB
hg commit
hg import revB.patch
hg up revA
hg branch branchC
hg commit
hg import revC.patch
And now you've got two named branches diverging from revA. If you have merges in the areas between revA->revB or revA->revC, I'm not sure this will preserve them perfectly.
Another alternative is to use the transplant extension. Or you could just push your clones' changes into one repo, and then move the heads that creates to new branches.