如何使用 Mercurial 队列将工作拆分为多个补丁?

发布于 2024-08-19 07:48:14 字数 1014 浏览 4 评论 0原文

如果我已经编写代码有一段时间了,并且忘记了创建补丁系列,那么如何回顾性地创建补丁系列?到目前为止,我唯一想到的是:

# Prepare and test the first batch of changes.
$ hg qrecord -m 'first batch' 1.patch
$ hg qnew -m 'stash downstream changes' stash-1.patch
$ hg qdelete -k temp-1.patch
$ make hello
cc     hello.c   -o hello
hello.c: In function ‘main’:
hello.c:4: error: syntax error at end of input
make: *** [hello] Error 1
$ echo '}' >> hello.c
$ make hello
cc     hello.c   -o hello
$ hg qrefresh

# Recover the stashed changes.
$ patch -p1 < .hg/patches/last.patch

# And around we go again!
$ hg qrecord -m 'second batch' 2.patch
$ hg qnew -m 'stash downstream changes' stash-2.patch
$ hg qdelete -k stash-2.patch
$ make hello
...

这种非常麻烦的方法也很危险。我可能会忘记 qdelete 上的 -k,此时我会用前额撞砖墙几分钟,或者我可能包含太多或太少在 qrecord 操作期间。

有更好的办法吗?

(我真正想要的是能够 hg qpop 到我想要分割的补丁之前,并使用当前不存在的命令,hg qunrecord,以交互方式将补丁中的更改吸到我的工作目录中。一旦我对更改感到满意,hg qnew -f 就可以在旧补丁前面压缩一个新补丁。)

If I've been churning away at the code for a while, and forgotten to create a patch series as I go, how do I create the patch series retrospectively? So far the only thing that comes to mind is:

# Prepare and test the first batch of changes.
$ hg qrecord -m 'first batch' 1.patch
$ hg qnew -m 'stash downstream changes' stash-1.patch
$ hg qdelete -k temp-1.patch
$ make hello
cc     hello.c   -o hello
hello.c: In function ‘main’:
hello.c:4: error: syntax error at end of input
make: *** [hello] Error 1
$ echo '}' >> hello.c
$ make hello
cc     hello.c   -o hello
$ hg qrefresh

# Recover the stashed changes.
$ patch -p1 < .hg/patches/last.patch

# And around we go again!
$ hg qrecord -m 'second batch' 2.patch
$ hg qnew -m 'stash downstream changes' stash-2.patch
$ hg qdelete -k stash-2.patch
$ make hello
...

This very cumbersome approach is also hazardous. I might forget the -k on qdelete, at which point I'll go bash my forehead against a brick wall for several minutes, or I might include too much or too little during the qrecord operation.

Is there a better way?

(What I'd really like is to be able to hg qpop to just before a patch I want to split, and use a currently non-existent command, hg qunrecord, to interactively suck changes out of the patch into my working directory. Once I'm happy with the changes, hg qnew -f could squeeze a new patch in front of the old one.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

感悟人生的甜 2024-08-26 07:48:14

MQTutorial 解释了如何拆分补丁。因此,您可以根据当前工作创建一个补丁并将其拆分为多个补丁。

The MQTutorial explains how to split patches. So you could create a patch from you current work and split it into several patches.

若无相欠,怎会相见 2024-08-26 07:48:14

TortoiseHg 在“提交”对话框中具有非常有用的功能“Hunk Selection”,用于此类工作:
http://tortoisehg.bitbucket.io/manual/2.0/commit。 html#change-selection

TortoiseHg has very useful feature "Hunk Selection" in Commit dialog for kind of this work:
http://tortoisehg.bitbucket.io/manual/2.0/commit.html#change-selection

眼泪淡了忧伤 2024-08-26 07:48:14

我认为 crecord 扩展 可以让你做到这一点。它为您提供了一个基于诅咒的交互式界面,您可以在其中准确选择提交中的内容。

I think the crecord extension will let you do this. It gives you an interactive curses based interface where you can choose exactly what's in a commit.

红颜悴 2024-08-26 07:48:14

启用内置扩展:

[extensions]
mq=
record=
shelve=

然后将 MQ 移入工作树并拆分更改并删除原始补丁:

$ hg qpop my.patch
$ patch -p1 <.hg/patches/my.patch

$ hg qnew -i my1.patch
 ....
$ hg qnew -i my2.patch
 ....
$ hg qnew myN.patch   # last without interactive stuff

$ hg qdelete --keep my.patch

my$i.patchmy$((i+1)).patch 之间code> 您可以使用 hg shelve/hg unshelve 来测试项目是否已构建并在 my$i.patch 之上通过测试,而无需后续更改!

如果您发现此阶段缺少某些内容,请对搁置的更改使用 hg qref 或对未搁置的更改使用 hg qref -i

另请参阅 Mercurial:将 MQ 补丁移至搁置?

Enable built-in extensions:

[extensions]
mq=
record=
shelve=

Then move MQ into working tree and split changes and remove original patch:

$ hg qpop my.patch
$ patch -p1 <.hg/patches/my.patch

$ hg qnew -i my1.patch
 ....
$ hg qnew -i my2.patch
 ....
$ hg qnew myN.patch   # last without interactive stuff

$ hg qdelete --keep my.patch

Between my$i.patch and my$((i+1)).patch you can use hg shelve/hg unshelve to test if project built and pass tests on top of my$i.patch without later changes!

If you find that something missing on this stage use hg qref on shelved changes or hg qref -i on unshelved changes!

See also Mercurial: move MQ patch to shelve?

葮薆情 2024-08-26 07:48:14

首先,安装 crecord,因为它只是一种更好的拆分更改的方式。

$ hg qcrecord part1
$ hg qnew part2 # ok, slightly a lie at this point
$ hg qpop
$ echo "}" >> hello.c
$ hg qrefresh
$ hg qpush
$ hg qcrefresh # Keep just what you want in part2
$ ...

这里 crecord 唯一特殊的是 qcrefresh 命令。如果您不是 Curses 粉丝,您仍然可以在这里执行所有相同的操作,只需将 qcrefresh 替换为 hg qrefresh -X 're:.' 即可。如果您愿意,也可以使用 hg qrefresh -I aauuuuuggghhh 。 (这是您使用 -X 或 -I 的“取消提交”。)

First, install crecord because it is just a way way nicer way of splitting changes up.

$ hg qcrecord part1
$ hg qnew part2 # ok, slightly a lie at this point
$ hg qpop
$ echo "}" >> hello.c
$ hg qrefresh
$ hg qpush
$ hg qcrefresh # Keep just what you want in part2
$ ...

The only thing special to crecord here is the qcrefresh command. If you're not a curses fan, you can still do all of the same stuff here, just replace qcrefresh with hg qrefresh -X 're:.'. Or hg qrefresh -I aauuuuuggghhh if you'd prefer. (It's your "uncommit" using -X or -I.)

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