编辑git patch给出"你编辑的hunk不适用"

BiA*_*AiB 11 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
Run Code Online (Sandbox Code Playgroud)

ps:这些是这里唯一的修改过的行

我想删除

+                       <a class="checkTool"></a>
Run Code Online (Sandbox Code Playgroud)

所以我这样编辑:

# 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.
Run Code Online (Sandbox Code Playgroud)

并且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]? 
Run Code Online (Sandbox Code Playgroud)

对我来说,我没有看到我写的任何错误或含糊之处,所以我错在哪里?

ant*_*tho 11

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

许多文本编辑在保存时剪切了尾随的空格,请注意这一点.

第二件事,当删除" - "以保持一条线时,实际上用空格""替换它,不要只删除它.

最后,不要在顶部的@@ @@中输入数字.

  • @NiklasR从Git版本2.11.0开始,您不需要在顶部调整@@ @@中的班轮号码,因为对未修改的行进行更改**必须**在实际代码中而不是在交互模式下手动编辑.git交互模式将自行处理修改后的行调整. (3认同)
  • 如果行数更改,则必须在顶部@@ @@中调整班轮号。 (2认同)
  • 对我来说,关键字是_replace_。我只是删除了“-”字符(不是整行),然后补丁也没有应用。删除“-”并添加一个空格就可以了。 (2认同)