是否有相当于`git stash save -p`的汞可以将大块分割成更小的块? [英] Is there an hg equivalent of `git stash save -p` that can split chunks into smaller chunks?
问题描述
我只想提交对文件所做的一些修改,而我这样做的首选方法是搁置/存储我不想提交的更改.这使我可以在实际提交更改之前测试要提交的更改.
I want to commit only some of the modifications I made to my files and my preferred way to do this is to shelve/stash away the changes I don't want to commit. This allows me to test the changes I will commit before actually commiting them.
我遇到的问题是,当我在tortoisehg中使用搁架"工具时,我找不到任何将一块分成两个较小的块的方法.例如,我有一个看起来像这样的块:
The problem I am having is that when I use the "shelve" tool in tortoisehg I can't find any way to split a chunk into two smaller chunks. For example, I have a chunk that looks like this:
@@ -1,1 +1,2 @@
-hallo world
+hello world
+something else
我想搁置其他",所以我只能提交"hallo-> hello"修复程序.但是,由于tortoisehg看到的只有一个块,所以我既可以搁置这两个更改,也可以不搁置任何更改.
I would like to shelve away the "something else" so I can commit just the "hallo->hello" fix. However, since tortoisehg is seeing this a single chunk I can either shelve both or none of the changes.
我也尝试通过命令行使用shelve扩展名,但是据我从文档中了解到,它没有提供仅保留部分文件的功能.
I also tried using the shelve extension via the command line but from what I understood from the documentation it does not offer the feature to shelve away only parts of the files.
推荐答案
您可以从命令行完成目标.有hg commit
,hg revert
和hg shelve
的交互式版本,它们具有低级选项,可以根据需要一起破解补丁.您可以将它们与-i
(或--interactive
)命令行选项一起使用.
You can accomplish your goal from the command line. There are interactive versions of hg commit
, hg revert
, and hg shelve
, and they have low-level options to hack a patch together if needed; you can use them with the -i
(or --interactive
) command line option.
这意味着您可以使用hg commit -i
和hg commit --amend -i
建立提交.如果您安装了Evolution扩展,则可以使用hg uncommit
再次将更改从提交中拉出;否则,请执行以下操作.如果不是,则可以使用hg revert -r .~1
或hg revert -i -r .~1
文件,然后再次使用hg commit --amend -i
对其进行修复.
This means that you can build up a commit with hg commit -i
and hg commit --amend -i
. If you have the evolve extension installed, you can use hg uncommit
to pull changes out of the commit again; if not, you can use hg revert -r .~1
or hg revert -i -r .~1
a file and use hg commit --amend -i
again to fix it up.
为了从补丁中选择单独的行,您有两个选择.您可以使用e
编辑补丁(但请参阅下面的更方便的选项).
In order to select individual lines from a patch, you have two options. You can use e
to edit the patch (but see below for a more convenient option).
然后您可以使用hg shelve
搁置其余更改.
You can then use hg shelve
to shelve the remaining changes.
原则上,您也可以使用hg shelve -i
进行此操作,但是有一个很大的警告;如果您为hg shelve -i
编辑补丁,那么Mercurial的合并机制将变得混乱,无法干净地处理更改,而是将您转储到合并工具中以解决此明显的冲突(这意味着要解决许多额外的工作).因此,为什么我强烈建议使用hg commit -i
和hg commit --amend -i
如果要在行级别进行操作(如果不编辑补丁,则hg shelve -i
可以很好地工作).
You can in principle also do this with hg shelve -i
, however, there's a big caveat; if you edit patches for hg shelve -i
, then Mercurial's merge mechanism will get confused and not process the change cleanly, but dump you in a merge tool in order to resolve this apparent conflict (which means lots of extra work to resolve it). Hence why I strongly recommend using hg commit -i
and hg commit --amend -i
if you want to manipulate things at the line level (hg shelve -i
works fine if you don't edit the patches).
为了增加便利性(阻止您编辑补丁),还可以通过将以下内容添加到hgrc
文件中来启用实验性crecord选项:
For added convenience (that prevents you from editing patches), you can also enable the experimental crecord option by adding the following to your hgrc
file:
[experimental]
crecord = true
这将为hg commit -i
,hg revert -i
和hg shelve -i
启用基于终端的块编辑器,使您可以选择单个行和块(在内部,其工作方式与编辑补丁相同).使用?
键在该编辑器中获取帮助.使用f
展开/折叠单个块,并使用空格键选择块/线.
This will enable a terminal-based hunk editor for hg commit -i
, hg revert -i
, and hg shelve -i
that allows you to select individual lines and hunks (internally, that works roughly the same way as editing patches). Use the ?
key to get help in that editor; use f
to unfold/fold individual hunks and the space key to select hunks/lines.
请注意,此工具与hg shelve -i
结合使用时,基于行的选择具有与编辑补丁相同的警告;即如果要进行基于行的选择,请改用hg commit -i
和hg commit --amend -i
.同样,hg revert -i
的基于行的选择仍将还原整个块. (有一个原因为什么该选项仍被标记为实验性.)
Note that line-based selection for this tool in conjunction with hg shelve -i
comes with the same caveats as editing patches; i.e. use hg commit -i
and hg commit --amend -i
instead if you want to do line-based selection. Also, line-based selection for hg revert -i
will still revert the entire hunk. (There's a reason why this option is still marked as experimental.)
这篇关于是否有相当于`git stash save -p`的汞可以将大块分割成更小的块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!