klenwell information services : MercurialBranches

Wiki source for MercurialBranches


Show raw source

=====Mercurial Branches=====
return to DevMercurial

**Note**: it is always advisable to copy your repository and test out these steps on the copy before proceeding.

====Create a New Branch====
Simple Example: Create a new branch, switch to it, and switch back to default
%%
# Check Current Branch
$ hg branch
default

# Create New Branch
$ hg branch new-branch
marked working directory as branch new-branch

# Confirm New Branch
$ hg branch
new-branch

# List Branches (Several Weeks Later)
$ hg branches
new-branch 200:ad96a97024ce
default 100:019016980509 (inactive)

# Switch Back to Default
$ hg update -C default

# Confirm Switch
$ hg branch
default
%%

====Merging Branches====
Simple Example: merge new-branch back into default
%%
$ hg branches
new-branch 200:ad96a97024ce
default 100:019016980509 (inactive)

$ hg branch
new-branch

$ hg update -C default
10 files updated, 0 files merged, 5 files removed, 0 files unresolved
(branch merge, don't forget to commit)

$ hg merge new-branch

$ hg commit -m "merged new-branch back into default"

$ hg branch
default
%%

Usage
%%
$ hg merge --usage
hg merge: option --usage not recognized
hg merge [-f] [[-r] REV]

merge working directory with another revision

Merge the contents of the current working directory and the
requested revision. Files that changed between either parent are
marked as changed for the next commit and a commit must be
performed before any further updates are allowed.

If no revision is specified, the working directory's parent is a
head revision, and the repository contains exactly one other head,
the other head is merged with by default. Otherwise, an explicit
revision to merge with must be provided.

options:

-f --force force a merge with outstanding changes
-r --rev revision to merge
%%

====Closing Branches====
ref: http://stackoverflow.com/a/3228023/1093087

%%
$ hg update new-branch
$ hg commit -m "closing new-branch" --close-branch
%%

====References====
[[http://stackoverflow.com/questions/50223/how-to-repeatedly-merge-branches-in-mercurial/50475#50475 | Merge Branches in Mercurial]] (stackoverflow.com)
[[http://mercurial.selenic.com/wiki/NamedBranches | Named Branches]] (mercurial.selenic.com)