I already read topics like How to correctly close a feature branch in Mercurial?
But I want remove branches reference.
Example
hg branch my-branch
hg commit -m "commit" --close-branch
hg branches -c
hg branches -c displays my-branch in the list. And I can't create a new branch named my-branch.
hg branch my-branch
Mercurial shows me an error :
abort: a branch of the same name already exists
Do you know how to remove branch reference definitively ?
hg help branch
...
options:
-f --force set branch name even if it shadows an existing branch
...
Related
I need to replace the contents of master with the contents of a branch. I can find details on how to do this in Git, but nothing for Mercurial.
Example Q for Git
Replacing master with another branch
My setup is
master
newbranch
I want the 'master' to be identical to 'newbranch
The basic choice you have is "rebase or merge": https://blog.sourcetreeapp.com/2012/08/21/merge-or-rebase/
Here on SO, a helpful Q&A is at:
Make another branch default?
The remainder of this response borrows from that page.
If you want to close the "feature-branch":
$ hg checkout default
$ hg merge feature-branch
$ hg commit
$ hg checkout feature-branch
$ hg commit --close-branch
The simplicity of the revert/commit approach mentioned there also has much to recommend it:
hg revert --all --rev ${1}
hg commit -m "Restoring branch ${1} as default"
where ${1} is (for example) the name of the relevant branch.
Doesn't the first approach assume there are no conflicts between the "default" and "feature branch"? When you desire to replace code, the assumption is that there ARE conflicts, and all should be resolved treating the "feature branch" as authoritative.
With mercurial it is easy to create a tag at a certain revision: hg tag -r <revision> <tag-name>. But how to create a branch at a certain revision?
Preface: Mercurial branches are two types:
named branch
anonymous
Named Branch
In order to get named branch BRANCHNAME, starting at REV
hg update REV
hg branch BRANCHNAME
...
hg commit
commit is a must, because
the branch will not exist in the repository until the next commit
as noted in hg help branch
Anonymous branch
hg update REV
...
hg commit
and current branch get additional head
And as a last step, use the following command to create a remote branch and push the changesets.
hg push --new-branch
You could you hg clone -r <rev>. From the command line help (run hg -v help clone):
- create a repository without changesets after a particular revision:
hg clone -r 04e544 experimental/ good/
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.
I'm trying to figure out how to merge branches from a separate repo into the current.
I have the following:
PJT1
- contains branches default and foodog
PJT2
- contains branch default
from PJT2, I do the following:
$ hg fetch -y ../PJT1 -r foodog -m "this is a test"
Now, if I look in PJT2, I see the correct files and changes. However, I if I do hg branches, I get the following:
[someone#myhome pjt2]$ hg branches
foodog 1:c1e14fde816b
default 0:7b1adb938f71 (inactive)
and hg branch reveals the following:
[someone#myhome pjt2]$ hg branch
foodog
How do I get the contents from PJT1's foodog branch into PJT2's default branch?
You need to merge, but keep in mind changes on branch foodog will always be on foodog -- branches never go away but they can be hidden. This sequence of commands is as close as you'll get to what you're asking:
cd PJT2
hg update default # just in case you were somewhere else
hg pull ../PJT1 -r foodog # that gets you foodog
hg merge foodog # that merges the changes into default
hg commit # commit the merge
hg update foodog # go to the most recent change in foodog (note: it is not a 'head')
hg commit --close-branch
After the merge hg branches will still show foodog unless you do hg branches --active which only shows branches that have heads on them. After the commit --close-branch you won't see foodog unless you do hg branches --closed.
It's because branches in Mercurial never go away entirely (a design feature) that they're often reserved only for life-long things like release-1.0 or stable. For short-lived efforts like bugs and features consider using bookmarks instead. Here's a great comparison of the two: http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial
You could also try using the rebase extension. It would look something like this:
hg fetch -y ../PJT1 -r foodog -m "this is a test"
hg rebase --source <sRev> --dest <dRev>
The rebase action will detatch changeset sRev and all descendents and apply the group of changes to changeset dRev. By default, the changes will be applied on the default branch. So, in your case, sRev would be the first changeset on branch foodog and dRev would be the default changeset you want to apply them to.
Finally, If you want to override this and preserve the source branch name you can use rebase option --keepbranches. Your questions indicates that this is exactly what you do not want to do, but it should still be noted.
If I create a branch:
hg branch branch-A
and commit to it:
hg commit -m "improvement A-1"
and then create a second branch:
hg branch branch-B
and commit to it:
hg commit -m "improvement B-1"
If I want to add my next change to branch-A do I simply type:
hg branch branch-A
and commit to it as before:
hg commit -m "improvement A-2"
hg branch
always creates a branch (although it warns you if the branch already exists.) To switch to an existing branch, either
hg update -r <some revision in that branch>
or
hg update <that branch>
will switch to that branch.