编辑git补丁会导致“您编辑的大块不适用” [英] editing git patch gives "Your edited hunk does not apply"
问题描述
我以交互方式添加文件:
I'm adding a file interactively:
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:这里是唯一修改过的行
ps: those are the only modified lines here
我想删除
I want to remove
+ <a class="checkTool"></a>
所以我编辑如下:
so I edit like this:
# 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拒绝了它:
and git refused it:
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]?
对我而言,我看不到任何错误或含糊不清,所以我错在哪里?
To me I don't see any error or ambiguity in what I wrote, so where Am I wrong?
推荐答案
ydroneaud的评论是我寻找的答案。
ydroneaud's comment was the answer I was looking for.
许多文本编辑器在保存时会剪掉尾随的空格,注意这一点。
Many text editors cut trailing white spaces when saving, look out for that.
第二件事,当删除一个 - 以保留一行时,实际上用一个空格,不要只是删除它。
Second thing, when removing a "-" to keep a line, actually replace it with a space " ", don't just delete it.
最后一点,不要在@@ @@的顶部数字。
Last thing, don't fiddle with the numbers in @@ @@ at the top.
这篇关于编辑git补丁会导致“您编辑的大块不适用”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!