Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

editing git patch gives "Your edited hunk does not apply"

Tags:

git

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

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?

like image 932
BiAiB Avatar asked Feb 29 '12 14:02

BiAiB


1 Answers

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.

like image 176
antho Avatar answered Sep 27 '22 23:09

antho