使用 Mercurial,我如何“压缩”数据? 在推送之前将一系列变更集合并为一个?
假设我有一个本地和一个远程 Mercurial 存储库。 现在,我开始开发一个功能。 我致力于它,当我认为它已经完成时,我提交变更集。 多测试一下,我发现我可以通过调整代码中的某些内容来进一步改进此功能。 我做出改变并承诺。 20 分钟后,我发现这个新功能有一个 bug,所以我修复了它并提交了它。
例如,我现在有 3 个变更集,我真的很想将它们作为一个带有消息“实现功能 X”的变更集推送到远程存储库。
我怎样才能轻松地做到这一点? 我相信我可以通过补丁来做到这一点,但这似乎需要很多工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
histedit 扩展正是您所寻找的。
或
将显示传出变更集的列表。 从列表中,您可以
histedit 将提示您输入折叠变更集的新提交消息,默认为两条消息,并用“\n***\n”分隔它们。
您也可以使用 mq 扩展获得类似的结果,但要困难得多。
您还可以使用折叠扩展来进行折叠,但它没有提供很好的 UI,也没有提供编辑生成的提交消息的方法。 编辑生成的提交消息还可以清理最终消息,这是我最终经常使用的东西。
The histedit extension is exactly what you are looking for.
or
will bring up a list of the outgoing changesets. From the list you can
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.
折叠扩展怎么样?
How about the Collapse Extension?
是的,您可以使用补丁来做到这一点:
假设您的工作位于变更集 100 到 110 中,包括
创建补丁:
% hg export -o mypatch 100:110 --git
% hg update 99
使用 --no-commit 应用补丁(否则你会取回所有变更集):
% hg import --no-commit mypatch
立即提交所有更改:
% hg commit
您现在有两个头(110 和 111),它们应该是等效的就它们在您的工作目录中生成的文件而言——也许在删除旧文件之前先对它们进行比较以确保完整性:
% hg strip 100
好吧,现在我已经把它全部拼出来了,它看起来确实很长,但是我自己做了很多次,我觉得它不适合太麻烦了...
Yes, you can do it with patches:
Let's assume your work is in changesets 100 through 110, inclusive
Create a patch:
% hg export -o mypatch 100:110 --git
Update to 99:
% hg update 99
Apply the patch with --no-commit (otherwise you'll get all your changesets back):
% hg import --no-commit mypatch
Commit all changes at once:
% hg commit
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...
如果您使用TortoiseHg,则只需选择两个修订版(使用CTRL 选择非后续修订版),右键单击并选择“压缩历史记录”。
之后,您将在新头中获得一个新的更改列表,从您之前选择的第一个更改开始,它将包含您选择的更改列表之间的所有后代更改列表。
如果不再需要旧的更改列表,您可以简单地删除它们:使用 MQ 扩展。 再次,在 TortoiseHg 中:右键单击需要剥离其所有后代的第一个更改列表,“修改历史记录 -> 剥离”。
If you are using TortoiseHg, use can just select two revisions (use CTRL to select non-subsequent ones), right click and select "Compress History".
After that you'll get a new change list in new head starting from the first change you selected before, it will contain all descendant change lists between the ones you selected.
You can simply strip out old change lists if you don't need them anymore: use MQ extensions for it. Again, in TortoiseHg: right click on the first change list that needs to be stripped with all it's descendants, "Modify History -> Strip".
我使用 mq 进行此折叠的首选方法是使用 TortoiseHg 如此处所述。 然而,它可以很容易地从命令行完成,如下所示:(
可能有更好的方法来执行 qfold 步骤,但我不知道它,因为我通常使用 TortoiseHg 进行该操作。)
这似乎有点一开始很复杂,但是一旦您开始使用 mq,它就会变得非常简单和自然——而且您还可以使用 mq 做各种其他事情,这非常方便!
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:
(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!
hg crash
和hg histedit
是最好的方法。 或者,更确切地说,如果它们工作可靠的话,这将是最好的方法......我让histedit
在三分钟内因堆栈转储而崩溃。Collapse
也好不了多少。我想我可能会分享另外两个 BKM:
hg rebase --collapse
此扩展随 Mercurial 一起分发。 我还没有遇到任何问题。 您可能需要玩一些游戏才能解决
hg rebase
限制 - 基本上,它不喜欢在同一分支(命名或默认)上重新定基到祖先,尽管如果在之间重新定基,它确实允许这样做(命名)分支。将存储库 (
foo/.hg
) 移动到工作目录 (bar
) 及其文件。 反之则不然。有些人讨论过创建两个克隆树,并在它们之间复制文件。 或者在它们之间进行修补。 相反,移动
.hg
目录更容易。只要真正的存储库(
.hg
树)独立于工作目录及其文件,这种方法就有效。如果他们不独立...
hg collapse
andhg histedit
are the best ways. Or, rather, would be the best ways, if they worked reliably... I gothistedit
to crash with a stack dump within three minutes.Collapse
is not that much better.Thought I might share two other BKMs:
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.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.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...
我从未使用过 Mercurial,但这听起来很像 Martin Fowler 不久前在他的博客上谈论的内容:
http://martinfowler.com/bliki/MercurialSquashCommit.html
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
为什么不直接使用 hg strip --keep 命令呢?
然后您可以将所有更改作为一次提交来提交。
Why not just
hg strip --keep
command?Then you can commit all changes as a one commit.
HistEdit 会做你想做的事,但这可能有点矫枉过正。 如果您唯一需要的是将一些变更集折叠在一起,折叠扩展将完成这项工作。
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.
假设您在 Mercurial 中有两个未发布的
THIS
和THAT
提交,并希望它们在THIS
点加入单个提交::检查您的提交是否未发布::
更新到
LAST
提交::并将最多
THIS
的提交导入到 MQ::取消应用所有补丁并仅应用第一个
THIS
>::加入
THAT
::NOTE 要查找名称
THATNAME
使用::应用所有补丁并将它们移动到存储库历史记录::
我的博客主题帖子是在 Mercurial 中加入两个提交。
Suppose you have two unpublished
THIS
andTHAT
commits in Mercurial and like them to join into single commit atTHIS
point::Check that your commits are not published::
Update to
LAST
commit::and import commits up to
THIS
into MQ::Un-apply all patches and apply only first
THIS
::Join with
THAT
::NOTE To find name
THATNAME
use::Apply all patches and move them to repository history::
My blog post on subject is Joining two commits in Mercurial.
是的,
strip --keep
适用于作者的问题。 但它与其他版本略有不同,例如,如果您有版本从 1 到 30,但只想折叠版本 12-15。 其他解决方案有效,但不能strip --keep
。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 notstrip --keep
.