Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2008-03-23 15:59:12
Size: 425
Editor: abuehl
Comment: moved from TipsAndTricks/Intermediate
Revision 4 as of 2008-03-24 14:13:05
Size: 2712
Editor: abuehl
Comment: potential closing branches feature
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
If you've got a dead [:Branch:branch] you'd like to eliminate from the list of heads, you can do a 'no-op merge' to remove it: If you've got a dead [:Branch:branch] you'd like to eliminate from the list of [:Head:heads], you can do a 'no-op merge' to remove it:
Line 11: Line 11:

=== Why this might be bad ===

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

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.

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 jet another line of devlopment 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".

=== 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]).

=== Closing branches ===

There was a proposal about a new "closing branches" feature for Mercurial on the mailing list. A variant was discussed to add a new flag to changesets, which – when set – indicates that a branch (or head) is to be considered "closed". This closing changeset would typically contain no modifications to tracked files.

Closing a branch with head H would then be done by committing a new changeset C having H as parent and setting that "closed" flag in C. Other hg commands would then respect that flag, for example {{{hg heads}}} might then return only heads taht are not closed.

Pruning dead branches

If you've got a dead [:Branch:branch] you'd like to eliminate from the list of [:Head:heads], you can do a 'no-op merge' to remove it:

$ 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

1. Why this might be bad

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

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.

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 jet another line of devlopment 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".

2. 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]).

3. Closing branches

There was a proposal about a new "closing branches" feature for Mercurial on the mailing list. A variant was discussed to add a new flag to changesets, which – when set – indicates that a branch (or head) is to be considered "closed". This closing changeset would typically contain no modifications to tracked files.

Closing a branch with head H would then be done by committing a new changeset C having H as parent and setting that "closed" flag in C. Other hg commands would then respect that flag, for example hg heads might then return only heads taht are not closed.


CategoryTipsAndTricks

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