views:

840

answers:

5

Hi,

Let's say I have a local and a remote Mercurial repository. Now, I start working on a feature. I work on it, and when I think it's done, I commit the changeset. Testing it a bit more, I find that I could further improve this feature by tweaking something in the code. I make the change and commit. 20 minutes later, I find there's a bug in this new feature, so I fix it and commit that too.

I now have 3 changesets that I would really like to push to the remote repository as one changeset with message "Implementing feature X", for instance.

How can I do this without much hassle? I believe I could do it with patches, but it seems like a lot of work.

+2  A: 

I've never used Mercurial, but this sounds a lot like what Martin Fowler was talking about on his blog not too long ago:

http://martinfowler.com/bliki/MercurialSquashCommit.html

Joseph
That looks more than a bit complicated, but thanks for the link. Honestly I'm hoping for some magical extension that will do just what I want, like fetch and transplant did with pulling and cherry-picking changsets.
Lucas
+9  A: 

How about the Collapse Extension?

Steve Losh
God bless you, this is _exactly_ what I wanted. :D
Lucas
+2  A: 

Yes, you can do it with patches: Let's assume your work is in changesets 100 through 110, inclusive

  1. Create a patch:

    % hg export -o mypatch 100:110

  2. Update to 99:

    % hg update 99

  3. Apply the patch with --no-commit (otherwise you'll get all your changesets back):

    % hg import --no-commit mypatch

  4. Commit all changes at once:

    % hg commit

  5. You now have two heads (110 and 111) which should be equivalent in terms of files they produce in your working directory -- maybe diff them for sanity before stripping the old ones out:

    % hg strip 100

OK, now that I have spelled it all out, it does seem lengthy, but having done it a bunch of times myself, I don't find it to be too much of a chore...

scrible
+11  A: 

The histedit extension is exactly what you are looking for.

hg histedit -o

or

hg histedit --outgoing

will bring up a list of the outgoing changesets. From the list you can

  • Fold 2 or more changesets creating one single changeset
  • Drop changesets removing them from the history
  • Reorder changesets however you like.

histedit will prompt you for the new commit message of the folded changesets which it defaults to the two messages with "\n***\n" separating them.

You can also get similar results using the mq extension, but it is a lot more difficult.

You can also use the collapse extension to just do folding, but it doesn't provide as nice a UI and doesn't provide a way to edit the resulting commit message. Editing the resulting commit message also allows for cleaning up the final message, which is something I always end up utilizing.

Stefan Rusek
thanks, thats exactly what i needed. It'd be nice if you could do it from within TortoiseHg - but the command line is simple enough.
sylvanaar
A: 

HistEdit will do what you want, but it's probably overkill. If the only thing you need is to fold some changesets together the Collapse Extension will do the job.

Steve Losh
though it does provide a much easier to use and understand UI, which is more than enough of a reason to use it, but it also provides a mechanism to edit the merged changeset message, which is another thing that I always want to do when I merge changesets.
Stefan Rusek