如何使用 Mercurial 队列将工作拆分为多个补丁?
如果我已经编写代码有一段时间了,并且忘记了创建补丁系列,那么如何回顾性地创建补丁系列?到目前为止,我唯一想到的是:
# 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
MQTutorial 解释了如何拆分补丁。因此,您可以根据当前工作创建一个补丁并将其拆分为多个补丁。
The MQTutorial explains how to split patches. So you could create a patch from you current work and split it into several patches.
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
我认为 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.
启用内置扩展:
然后将 MQ 移入工作树并拆分更改并删除原始补丁:
在
my$i.patch
和my$((i+1)).patch
之间code> 您可以使用hg shelve
/hg unshelve
来测试项目是否已构建并在my$i.patch
之上通过测试,而无需后续更改!如果您发现此阶段缺少某些内容,请对搁置的更改使用
hg qref
或对未搁置的更改使用hg qref -i
!另请参阅 Mercurial:将 MQ 补丁移至搁置?
Enable built-in extensions:
Then move MQ into working tree and split changes and remove original patch:
Between
my$i.patch
andmy$((i+1)).patch
you can usehg shelve
/hg unshelve
to test if project built and pass tests on top ofmy$i.patch
without later changes!If you find that something missing on this stage use
hg qref
on shelved changes orhg qref -i
on unshelved changes!See also Mercurial: move MQ patch to shelve?
首先,安装 crecord,因为它只是一种更好的拆分更改的方式。
这里 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.
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:.'
. Orhg qrefresh -I aauuuuuggghhh
if you'd prefer. (It's your "uncommit" using -X or -I.)