2012-02-29 83 views
9

我加入交互文件:编辑git的补丁提供了“修改过的猛男不适用”

git add ../../template/panels/panel-reports.php -p 
diff --git a/template/panels/panel-reports.php b/template/panels/panel-reports.php 
index 5482228..48d2901 100644 
--- a/template/panels/panel-reports.php 
+++ b/template/panels/panel-reports.php 
@@ -214,6 +214,8 @@ 

         <a class="addCategory"></a> 
         <a class="removeCategory"></a> 
+      <a class="addDocument"></a> 
+      <a class="checkTool"></a> 

         <div class="categoriesList"></div> 
         <div class="documentsList"></div> 
Stage this hunk [y,n,q,a,d,/,e,?]? e 

PS:那些是这里唯一的修饰线条

我想删除

+      <a class="checkTool"></a> 

所以我编辑是这样的:

# Manual hunk edit mode -- see bottom for a quick guide 
@@ -214,6 +214,7 @@ 

               <a class="addCategory"></a> 
               <a class="removeCategory"></a> 
+            <a class="addDocument"></a> 

               <div class="categoriesList"></div> 
               <div class="documentsList"></div> 
# --- 
# To remove '-' lines, make them ' ' lines (context). 
# To remove '+' lines, delete them. 
# Lines starting with # will be removed. 

和Git拒绝了:

error: patch failed: template/panels/panel-reports.php:214 
error: template/panels/panel-reports.php: patch does not apply 
Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]? 

对我来说,我没有看到我写的任何错误或歧义,所以我在哪里错了?

+3

确保每个上下文行以前导空格字符“'开头,即使该行是空的。 – ydroneaud 2012-02-29 16:33:42

+3

已浏览[此问题](http://stackoverflow.com/questions/3268596/git-add-interactive-your-edited-hunk-does-not-apply)。 – simont 2012-02-29 21:08:34

回答

8

ydroneaud的评论是我正在寻找的答案。

许多文本编辑器在保存时会切割尾随的白色空格,请注意这一点。

第二件事,当删除“ - ”以保留一行时,实际上用空格替换它“”,不要删除它。

最后一件事,不要在@@ @@顶端摆弄数字。

+1

如果行数发生变化,您必须在顶部@@ @@调整班轮编号。 – 2015-09-04 13:24:14

+1

@NiklasR作为Git版本2.11.0,您不需要在顶部调整@@ @@中的班轮编号,因为对未修改的行进行更改**必须在实际代码中比在交互模式下手动编辑。 git交互模式将处理修改后的行自行调整。 – Eido95 2017-04-18 20:35:24