Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2008-03-23 15:59:12
Size: 425
Editor: abuehl
Comment: moved from TipsAndTricks/Intermediate
Revision 3 as of 2008-03-24 13:51:56
Size: 2088
Editor: abuehl
Comment: expanding on why this could be a problem
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]).

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


CategoryTipsAndTricks

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