用`git add -p`解开两行 [英] Untangle two lines with `git add -p`

查看:113
本文介绍了用`git add -p`解开两行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #手动编辑模式 - 请参阅下方的快速编辑模式(foo)
{
bla();指导
@@ -280,6 +281,7 @@

- test(true);
+ removeThis();
+ test(false);
}
else

如何提交 test(),并避免提交removeThis()?
每次我尝试手动编辑hunk时,git都会告诉我它并没有干净地应用。

解决方案


我怎样才能仅仅改变test(),并避免提交removeThis()?


这很简单。
$ b


  1. 输入 add -i 模式,然后选择<$ c $按下 p Enter 键,即可打开c> 5:[p] atch 。

  2. 通过输入文件编号选择文件,然后按 Enter 开始编辑补丁。 $ b
  3. e 编辑您的大块(您似乎已通过 git add -p 代替成功到达) 。


  4. removeThis() 完全 code> + 在开始处标记。别碰别的东西!所产生的文本应该看起来像是您正在提交的更改的补丁。

  5. / strong>编辑器。

这个补丁很适用。我刚刚检查过。再次检查 - 也许这是另一个不适用的大块?



除此之外,您的符号靠近 + / - 看起来很可疑。也许,你的补丁程序 diff 程序有些不同步?尝试从大块中删除 s。


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.

解决方案

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.

这篇关于用`git add -p`解开两行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆