Differences between revisions 18 and 19
Revision 18 as of 2012-03-21 17:12:02
Size: 4528
Editor: gw
Comment:
Revision 19 as of 2015-04-01 12:53:10
Size: 4284
Editor: Eric Radman
Comment: Closed branches are not shown by default
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
Line 11: Line 10:
A branch may be closed by running the following commands:
Line 12: Line 12:
Mercurial version 1.2 introduced the ability to close a branch. This can be done by running the following commands:
Line 16: Line 15:
hg up -C default # switch back to "good" branch hg up -C default
Line 18: Line 17:
Line 21: Line 19:
Once a branch is closed it will display the closed state in {{{hg branches}}}. A closed branch is not considered active and will not be displayed if the --active option is given to branches. Once a branch is closed it will display the closed state in {{{hg branches}}}. A closed branch is not considered active and will not be displayed by default.
Line 25: Line 24:
badbranch 11:cd3e11a024bf (closed)
% hg branches --active
% hg branches --closed
Line 28: Line 26:
badbranch 11:cd3e11a024bf (closed)
Line 29: Line 28:

In addition {{{hg heads}}} (see [[Head]]) now accepts the --active option and will not display any heads that
have been marked closed if the option is specified
.
In addition {{{hg heads}}} (see [[Head]]) now accepts the --closed option.
Line 34: Line 31:
Line 43: Line 39:
Line 45: Line 40:
Line 48: Line 42:
Consider you have a clone of a project like Mercurial – let's say a clone of the [[CrewRepository|crew repository]] – and you do make a change C1 based on some changeset P from the crew repo and propose that to the crew members for inclusion into the project. Consider you have a clone of a project like Mercurial let's say a clone of the [[CrewRepository|crew repository]] and you do make a change C1 based on some changeset P from the crew repo and propose that to the crew members for inclusion into the project.
Line 53: Line 47:
Line 59: Line 52:
Line 65: Line 57:
Line 71: Line 62:
Line 79: Line 69:

Another option may be to strip your dead branch with {{{hg strip}}}, a command which is provided by the [[MqExtension]]:
Another option may be to strip your dead branch with {{{hg strip}}}, a command which is provided by the MqExtension:
Line 92: Line 81:

However, note that this is a non-history-preserving transformation of your repository. If anyone else has already pulled your C1 and used that as a parent for more changes, you might get that back if you pull from that person (The "Genie is out of the Bottle" problem, see also [[EditingHistory]]).
However, note that this is a non-history-preserving transformation of your repository. If anyone else has already pulled your C1 and used that as a parent for more changes, you might get that back if you pull from that person (The "Genie is out of the Bottle" problem, see also EditingHistory).

Other Languages: Zh

Pruning branches

There are three standard ways of managing branches that you no longer plan on working with. Each approach has advantages and disadvantages and should be selected on what best fits how you work with your repository.

1. Closing branches

A branch may be closed by running the following commands:

hg up -C badbranch
hg commit --close-branch -m 'close badbranch, this approach never worked'
hg up -C default

This creates a closing changeset which typically contains no modifications to tracked files. Closing changesets can be identified by close=1 in the changeset's extra field.

Once a branch is closed it will display the closed state in hg branches. A closed branch is not considered active and will not be displayed by default.

% hg branches
default                       12:d52ed2ac9127
% hg branches --closed
default                       12:d52ed2ac9127
badbranch                     11:cd3e11a024bf (closed)

In addition hg heads (see Head) now accepts the --closed option.

2. No-Op Merges

Another way is to do a "no-op merge" to remove the branch:

$ hg update -C tip # jump to one head
$ hg merge otherhead # merge in the other head
$ hg revert -a -r tip # undo all the changes from the merge
$ hg commit -m "eliminate other head" # create new tip identical to the old

2.1. Why this might be bad

The new merged head is based on the "eliminated" head, so it is not really eliminated. Furthermore, it is now incorporated into the main line, which actually may even be worse than simply letting that dead head alone.

Consider you have a clone of a project like Mercurial – let's say a clone of the crew repository – and you do make a change C1 based on some changeset P from the crew repo and propose that to the crew members for inclusion into the project.

If your change C1 is rejected or rebased on inclusion, you now have a dead branch C1 in your repo. If you merge that in your repo, you just create yet another line of development that is divergent from crew. So, in this case, merging your dead head doesn't make anything better as any new change you commit to your merged head won't be accepted for inclusion into crew anymore, since that would mean pulling-in your "eliminated" head as well. Such a new change would be said to not be "clean".

3. Using clone

The recommended procedure to really eliminate unwanted heads is to use hg clone --rev. First, you rename your current repo to a backup. Then you clone the backup back to the original name, but you specify --rev X where X is the parent of the first of the chain of wanted changesets. If your repository has other heads you need to preserve, specify them too, as additional --rev Y arguments. For example:

hg clone backup repo --rev X --rev Y

When you've cloned, verify that

hg incoming -R repo backup

really only shows the changesets you wanted to drop. If you discover changesets you do need, after all (for instance, another head you forgot to specify above), you can pull them over using

hg pull -R repo backup --rev Y

Repeat until you're satisfied with the pruned repo.

Copy over all non-tracked files you might want to preserve. In particular, you might want to copy .hg/hgrc from the backup since your default path now points to the backup instead of the original clone source.

You can remove your backup repository now.

4. Using strip

Another option may be to strip your dead branch with hg strip, a command which is provided by the MqExtension:

hg strip [-f] [-b] [-n] REV

strip a revision and all later revs on the same branch

options:

 -b --backup    bundle unrelated changesets
 -n --nobackup  no backups

However, note that this is a non-history-preserving transformation of your repository. If anyone else has already pulled your C1 and used that as a parent for more changes, you might get that back if you pull from that person (The "Genie is out of the Bottle" problem, see also EditingHistory).


CategoryTipsAndTricks

PruningDeadBranches (last edited 2022-12-26 20:11:56 by gavenkoa)