我可以用 git 拆分一个已经拆分的大块头吗? [英] Can I split an already split hunk with git?
问题描述
我最近发现了 add
命令的 git patch
选项,我必须说它确实是一个很棒的功能.我还发现可以通过点击 s 键将一个大块分成更小的块,这增加了提交的精度.但是如果我想要更高的精度,如果拆分的大块不够小怎么办?
I've recently discovered git's patch
option to the add
command, and I must say it really is a fantastic feature.
I also discovered that a large hunk could be split into smaller hunks by hitting the s key, which adds to the precision of the commit.
But what if I want even more precision, if the split hunk is not small enough?
例如,考虑这个已经分裂的大块头:
For example, consider this already split hunk:
@@ -34,12 +34,7 @@
width: 440px;
}
-/*#field_teacher_id {
- display: block;
-} */
-
-form.table-form #field_teacher + label,
-form.table-form #field_producer_distributor + label {
+#user-register form.table-form .field-type-checkbox label {
width: 300px;
}
如何仅将 CSS 注释删除添加到下一次提交?s
选项不再可用!
How can I add the CSS comment removal only to the next commit ? The s
option is not available anymore!
推荐答案
如果您使用 git add -p
并且即使在使用 s 拆分后,您也不会'没有足够小的改动,您可以使用e直接编辑补丁.
If you're using git add -p
and even after splitting with s, you don't have a small enough change, you can use e to edit the patch directly.
这可能有点令人困惑,但是如果您仔细按照按e后打开的编辑器窗口中的说明进行操作那么你会没事的.在您引用的情况下,您可能希望将 -
替换为这些行开头的空格:
This can be a little confusing, but if you carefully follow the instructions in the editor window that will be opened up after pressing e then you'll be fine. In the case you've quoted, you would want to replace the -
with a space at the beginning of these lines:
-
-form.table-form #field_teacher + label,
-form.table-form #field_producer_distributor + label {
... 并删除以下行,即以 +
开头的那一行.如果您随后保存并退出编辑器,则只会删除 CSS 注释.
... and delete the the following line, i.e. the one that begins with +
. If you then save and exit your editor, just the removal of the CSS comment will be staged.
这篇关于我可以用 git 拆分一个已经拆分的大块头吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!