使用 Mercurial,我如何“压缩”数据? 在推送之前将一系列变更集合并为一个?

发布于 2024-07-29 00:47:10 字数 285 浏览 4 评论 0原文

假设我有一个本地和一个远程 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

舞袖。长 2024-08-05 00:47:10

histedit 扩展正是您所寻找的。

hg histedit -o

hg histedit --outgoing

将显示传出变更集的列表。 从列表中,您可以

  • 折叠 2 个或更多变更集,创建一个变更集。
  • 删除变更集,将其从历史记录中删除,
  • 按照您喜欢的方式重新排序变更集。

histedit 将提示您输入折叠变更集的新提交消息,默认为两条消息,并用“\n***\n”分隔它们。

您也可以使用 mq 扩展获得类似的结果,但要困难得多。

您还可以使用折叠扩展来进行折叠,但它没有提供很好的 UI,也没有提供编辑生成的提交消息的方法。 编辑生成的提交消息还可以清理最终消息,这是我最终经常使用的东西。

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.

秋日私语 2024-08-05 00:47:10

折叠扩展怎么样?

How about the Collapse Extension?

坚持沉默 2024-08-05 00:47:10

是的,您可以使用补丁来做到这一点:
假设您的工作位于变更集 100 到 110 中,包括

  1. 创建补丁:

    % hg export -o mypatch 100:110 --git

  2. < p>更新到99:

    % hg update 99

  3. 使用 --no-commit 应用补丁(否则你会取回所有变更集):

    % hg import --no-commit mypatch

  4. 立即提交所有更改:

    % hg commit

  5. 您现在有两个头(110 和 111),它们应该是等效的就它们在您的工作目录中生成的文件而言——也许在删除旧文件之前先对它们进行比较以确保完整性:

    % hg strip 100

好吧,现在我已经把它全部拼出来了,它看起来确实很长,但是我自己做了很多次,我觉得它不适合太麻烦了...

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 --git

  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...

童话里做英雄 2024-08-05 00:47:10

如果您使用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".

一张白纸 2024-08-05 00:47:10

我使用 mq 进行此折叠的首选方法是使用 TortoiseHg 如此处所述。 然而,它可以很容易地从命令行完成,如下所示:(

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

可能有更好的方法来执行 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:

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!

旧话新听 2024-08-05 00:47:10

hg crashhg histedit 是最好的方法。 或者,更确切地说,如果它们工作可靠的话,这将是最好的方法......我让 histedit 在三分钟内因堆栈转储而崩溃。 Collapse 也好不了多少。

我想我可能会分享另外两个 BKM:

  1. hg rebase --collapse

    此扩展随 Mercurial 一起分发。 我还没有遇到任何问题。 您可能需要玩一些游戏才能解决 hg rebase 限制 - 基本上,它不喜欢在同一分支(命名或默认)上重新定基到祖先,尽管如果在之间重新定基,它确实允许这样做(命名)分支。

  2. 将存储库 (foo/.hg) 移动到工作目录 (bar) 及其文件。 反之则不然。

有些人讨论过创建两个克隆树,并在它们之间复制文件。 或者在它们之间进行修补。 相反,移动 .hg 目录更容易。

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

只要真正的存储库(.hg 树)独立于工作目录及其文件,这种方法就有效。

如果他们不独立​​...

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...

你又不是我 2024-08-05 00:47:10

我从未使用过 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

沙沙粒小 2024-08-05 00:47:10

为什么不直接使用 hg strip --keep 命令呢?

然后您可以将所有更改作为一次提交来提交。

Why not just hg strip --keep command?

Then you can commit all changes as a one commit.

各自安好 2024-08-05 00:47:10

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.

有木有妳兜一样 2024-08-05 00:47:10

假设您在 Mercurial 中有两个未发布的 THISTHAT 提交,并希望它们在 THIS 点加入单个提交::

... --> THIS --> ... --> THAT --> ... --> LAST

检查您的提交是否未发布::

$ hg glog -r "draft() & ($THIS | $THAT)"

更新到 LAST 提交::

$ hg up

并将最多 THIS 的提交导入到 MQ::

$ hg qimport $THIS::.

取消应用所有补丁并仅应用第一个 THIS >::

$ hg qpop -a
$ hg qpush
$ hg qapplied
... THIS ...

加入 THAT::

$ hg qfold $THATNAME

NOTE 要查找名称 THATNAME 使用::

$ hg qseries

应用所有补丁并将它们移动到存储库历史记录::

$ hg qpush -a
$ hg qfinish -a

我的博客主题帖子是在 Mercurial 中加入两个提交

Suppose you have two unpublished THIS and THAT commits in Mercurial and like them to join into single commit at THIS point::

... --> THIS --> ... --> THAT --> ... --> LAST

Check that your commits are not published::

$ hg glog -r "draft() & ($THIS | $THAT)"

Update to LAST commit::

$ hg up

and import commits up to THIS into MQ::

$ hg qimport $THIS::.

Un-apply all patches and apply only first THIS::

$ hg qpop -a
$ hg qpush
$ hg qapplied
... THIS ...

Join with THAT::

$ hg qfold $THATNAME

NOTE To find name THATNAME use::

$ hg qseries

Apply all patches and move them to repository history::

$ hg qpush -a
$ hg qfinish -a

My blog post on subject is Joining two commits in Mercurial.

晨光如昨 2024-08-05 00:47:10

是的,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 not strip --keep.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文