使用 git add -p 解开两行
我有一个包含以下更改的文件:
# Manual hunk edit mode -- see bottom for a quick guide
@@ -280,6 +281,7 @@
if( foo )
{
bla();
- test( true );
+ removeThis();
+ test( false );
}
else
如何仅提交 test()
的更改,并避免提交 removeThis() ? 每次我尝试手动编辑该块时,git 都会告诉我它不能完全应用。
I've got a file with the following changes:
# Manual hunk edit mode -- see bottom for a quick guide
@@ -280,6 +281,7 @@
if( foo )
{
bla();
- test( true );
+ removeThis();
+ test( false );
}
else
How can I commit the change for test()
only, and avoid committing removeThis() ?
Each time I try to edit the hunk manually git tells me it does not apply cleanly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很简单。
进入
add -i
模式,然后按pEnter选择5: [p]atch
。输入文件编号选择文件,然后按 Enter 开始编辑补丁。
输入文件编号选择
按e编辑你的块(你似乎已经通过执行
git add -p
成功到达这里)。使用
removeThis()
完全删除该行,并在开头加上+
符号。不要碰其他任何东西!生成的文本应该看起来像您所提交的更改的补丁。保存文件并退出编辑器。
该补丁将很好地应用。我刚刚检查过。也再检查一下——也许是另一个不适用的大块头?
除此之外,
+
/-
附近的,
符号看起来很可疑。也许,您的patch
和diff
程序在某种程度上不同步?尝试也从大块中删除,
。That's simple.
Enter
add -i
mode, then select5: [p]atch
by pressing pEnter.Choose your file by entering its number and press Enter to start editing patches.
Press e to edit your hunk (you seem to have succesfully reached here by doing
git add -p
instead).Delete the line with
removeThis()
completely, with+
sign at the beginning as well. Do not touch anything else! The resultant text should look like a patch for the change you're committing.Save the file and exit the editor.
The patch will apply well. I've just checked. Check again too--maybe it's another hunk that doesn't apply?
Other than that, your
,
symbols near the+
/-
look suspicious. Perhaps, yourpatch
anddiff
programs are somehow out of sync? Try removing the,
s from the hunk as well.