With Mercurial, how can I “compress” a series of c

2019-01-05 09:32发布

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.

11条回答
【Aperson】
2楼-- · 2019-01-05 09:46

Yes, strip --keep works for Author's question. But it was slightly different from others, for example, if you have version from 1 to 30 but only want to collapse version 12-15. Other solutions work but not strip --keep.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-05 09:53

My preferred method of using mq for this folding is using TortoiseHg as described here. However, it can easily be done from the command line like so:

hg qimport -r <first>:<last> 
    -- where <first> and <last> are the first and last changesets 
    -- in the range of revisions you want to collapse

hg qpop <first>.diff
    -- remove all except for the first patch from the queue
    -- note: mq names patches <#>.diff when it imports them, so we're using that here

hg qfold <next>.diff
    -- where <next> is <first>+1, then <first>+2, until you've reached <last>

hg qfinish -a
    -- apply the folded changeset back into the repository

(There may be a better way to do the qfold step, but I'm not aware of it, as I usually use TortoiseHg for that operation.)

It seems a little complicated at first, but once you've started using mq, it's pretty straightforward and natural -- plus you can do all kinds of other things with mq that can be pretty handy!

查看更多
beautiful°
4楼-- · 2019-01-05 09:55

hg collapse and hg histedit are the best ways. Or, rather, would be the best ways, if they worked reliably... I got histedit to crash with a stack dump within three minutes. Collapse is not that much better.

Thought I might share two other BKMs:

  1. hg rebase --collapse

    This extension is distributed with Mercurial. I haven't had problems with it yet. You may have to play some games to work around hg rebase limitations -- basically, it doesn't like rebasing to an ancestor on the same branch, named or default, although it does allow it if rebasing between (named) branches.

  2. Move the repository (foo/.hg) to the working directory (bar) and its files. Not the other way around.

Some people have talked about creating two clone trees, and copying files between them. Or patching between them. Instead, its easier to move the .hg directories.

hg clone project work
... lots of edits
... hg pull, merge, resolve
hg clone project, clean
mv work/.hg .hg.work
mv clean/.hg work/.hg
cd work
... if necessary, pull, nerge, reconcile - but that would only happen because of a race
hg push

This works as long as the true repositories, the .hg trees, are independent of the working directory and its files.

If they are not independent...

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-01-05 09:56

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

查看更多
\"骚年 ilove
6楼-- · 2019-01-05 09:58
叛逆
7楼-- · 2019-01-05 09:58

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.

查看更多
登录 后发表回答