使用 git add -p 解开两行

发布于 2024-08-23 20:16:43 字数 306 浏览 5 评论 0原文

我有一个包含以下更改的文件:

# 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 技术交流群。

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

发布评论

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

评论(1

情绪失控 2024-08-30 20:16:43

如何仅提交 test() 的更改,并避免提交 removeThis() ?

这很简单。

  1. 进入add -i模式,然后按pEnter选择5: [p]atch

  2. 输入文件编号选择文件,然后按 Enter 开始编辑补丁。

    输入文件编号选择

  3. e编辑你的块(你似乎已经通过执行git add -p成功到达这里)。

  4. 使用removeThis()完全删除该行,并在开头加上+符号。不要碰其他任何东西!生成的文本应该看起来像您所提交的更改的补丁。

  5. 保存文件并退出编辑器。

该补丁将很好地应用。我刚刚检查过。也再检查一下——也许是另一个不适用的大块头?

除此之外,+/- 附近的 , 符号看起来很可疑。也许,您的 patchdiff 程序在某种程度上不同步?尝试也从大块中删除 ,

How can I commit the change for test() only, and avoid committing removeThis() ?

That's simple.

  1. Enter add -i mode, then select 5: [p]atch by pressing pEnter.

  2. Choose your file by entering its number and press Enter to start editing patches.

  3. Press e to edit your hunk (you seem to have succesfully reached here by doing git add -p instead).

  4. 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.

  5. 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, your patch and diff programs are somehow out of sync? Try removing the ,s from the hunk as well.

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