0

I have a hg clone of a repository into which I have done numerous changes locally over a few months and pushed them to my clone at google code. Unfortunately as a noob I committed a whole bunch of changes on the default branch.

Now I would like to make sure my current default is EXACTLY as upstream and then I can do proper branching off default and only working on the branches..

However how do I do that cleanup though?

For reference my clone is http://code.google.com/r/mosabua-roboguice/source/browse

PS: I got my self into the same problem with git and got that cleaned up: Cleanup git master branch and move some commit to new branch?

Community
  • 1
  • 1
Manfred Moser
  • 29,539
  • 13
  • 92
  • 123

4 Answers4

2

First, there's nothing wrong with committing on the default branch. You generally don't want to create a separate named branch for every task in Mercurial, because named branches are forever. You might want to look at the bookmark feature for something closer to git branches ("hg help bookmarks"). So if the only thing wrong with your existing changesets is that they are on the default branch, then there really is nothing wrong with them. Don't worry about it.

However, if you really want to start afresh, the obvious, straightforward thing to do is reclone from upstream. You can keep your messy changesets by moving the existing repo and recloning. Then transplant the changesets from the old repo into the new one on a branch of your choosing.

If you don't want to spend the time/bandwidth for a new clone, you can use the (advanced, dangerous, not for beginners) strip command. First, you have to enable the mq extension (google it or see the manual -- I'm deliberately not explaining it here because it's dangerous). Then run

hg strip 'outgoing("http://upstream/path/to/repo")'

Note that I'm using the revsets feature added in Mercurial 1.7 here. If you're using an older version, there's no easy way to do this.

Greg Ward
  • 1,604
  • 1
  • 13
  • 13
  • Ok... so how would I maintain one branch or whatever in my clone that is exactly like upstream then so I can use it as a base for my development(s) and keep it clean and keep pulling in from upstream only. Or is there some other way I should do that? Because at the moment I am having a hard time pulling in from upstream due to lots of conflicts.. – Manfred Moser Sep 27 '11 at 03:48
  • +1 to Greg for pointing out that changes in default are okay. Named branches are forever and your upstream probably doesn't want them. – Ry4an Brase Sep 28 '11 at 01:57
1

Preface - all history changes have sense only for non-published repos. You'll have to push to GoogleCode's repo from scratch after editing local history (delete repo on GC, create empty, push) - otherwise you'll gust get one more HEAD in default branch

Manfred

Easy (but not short) way - default only+MQ

  1. as Greg mentioned, install MQ
  2. move all your commits into MQ-patches on top of upstream code
  3. leave your changes as pathes forever
  4. check, edit if nesessary and re-integrate patches after each upstream pull (this way your own CG-repo without MQ-patches will become identical to upstream)

More complex - MQ in the middle + separate branches

  1. above
  2. above
  3. create named branch, switch to it
  4. "Finish" patches
  5. Pull upstream, merge with your branch changes (from defaut to yourbranch)
  6. Commit your changes only into yourbranch

Rebasing

  1. Enable rebase extension
  2. Create named branch (with changeset in it? TBT)
  3. Rebase your changesets to the new ancestor, test results
  4. See 5-6 from "More complex" chapter
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • Thanks for the answer. At this stage it looks like too much work and I just recloned upstream and followed Ry4an's approach. – Manfred Moser Oct 04 '11 at 16:49
1

The best way to do this is with two clones. When working with a remote repo I don't control I always keep a local clone called 'virgin' to which I make no changes. For example:

hg clone -U https://code.google.com/r/mosabua-roboguice-clean/ mosabua-roboguice-clean-virgin
hg clone mosabua-roboguice-clean-virgin mosabua-roboguice-clean-working

Note that because Mercurial uses hard links for local clones and because that first clone was a clone with -U (no working directory (bare repo in git terms)) this takes up no additional disk space.

Work all you want in robo-guice working and pull in robo-guice virgin to see what's going on upstream, and pull again in roboguice-working to get upstream changes.

You can do something like this after the fact by creating a new clone of the remote repo and if diskspace is precious use the relink extension to associate them.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • Thanks. This is what I ended up doing based on a new clone. Cleaning up the old one seems to much effort. I updated the commands I had to use in your answer. – Manfred Moser Oct 04 '11 at 16:45
0

Perhaps you could try the Convert extension. It can bring a repository in a better shape, while preserving history. Of course, after the modifications have been done, you will have to delete the old repo and upload the converted one.

Geo
  • 93,257
  • 117
  • 344
  • 520