Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean revision history in Mercurial

Tags:

mercurial

I'm new with Mercurial and I'm still trying to establish a workflow.

I clone a remote repository. I then make changes and commits to my local repository. I would like to push a clean revision history. I don't want to push some revisions that may only muddy the remote repository (e.g. typo rename of methods, adding of javadoc, removing whitespaces, etc). Is this possible?

Thank you!

like image 554
Paul Avatar asked Sep 14 '11 09:09

Paul


1 Answers

Indeed there are cases when it makes sense to prune/strip/polish changesets or to separate private/in-progress and public/ready changes. Here are some suggestion how to handle this with Mercurial:

  1. If you made a series of small commits (which is a good thing), but you prefer to publish them as one changeset (which makes sense if you committed - possibly contradicting - snapshot changesets), use the collapse extension:

    $ hg collapse -r <first-ref>:<last-ref> # both revs including
    
  2. If you just have changes you want to keep private while others you want to publish, either (a) use mercurial queues for you private changes or (b) commit you private-only changes in an own branch (named, bookmarked, or cloned) and regularly merge it with the public branch. The latter requires you to switch between branches quite often if you commit private and public changes alternating.


UPDATE

To illustrate option 2.b, consider this graph of changesets:

0--1--4--5---8--9   <= public/stable branch
    \     \
     2--3--6--7     <= private/dev branch

This means you've made changes 2 and 3 on the dev branch. Then you did some work on the stable branch (revisions 4 and 5). These changes also make sense in dev, so you merge them into dev (revision 6). Finally you make another experimental change in dev (revision 7) and some ready-to-publish improvements in stable (revisions 8 and 9). You can now publish (i.e. push to the remote repository) the changes made in stable, by running

$ hg push -r 9     # or `-r stable` if the branch is named or bookmarked as such

All private changes will stay local!

Note that if you plan to polish your private commits later (e.g. collapse them to one changeset), you must not merge in the stable branch (collapse cannot work across merges). Instead, rebase you private changes whenever you want them to be in sync with the latest changes in stable.

like image 187
Oben Sonne Avatar answered Sep 30 '22 06:09

Oben Sonne