Sunday, 1 September 2013

Why doesn't this patch apply?

Why doesn't this patch apply?

I'm trying to use git add -p to stage a specific hunk of changes to the
index.
Here's the hunk as Git suggests:
@@ -7,8 +7,15 @@
<title>{{ page.title }}</title>
<link rel="stylesheet" href="/css/style.css">
</head>
- <body>
- <div class="content container">
+
+ <body class="container">
+ <ul class="navigation">
+ {% if page.url != '/index.html' %}
+ <li><a href="/">Home</a></li>
+ {% endif %}
+ </ul>
+
+ <div class="content">
{{ content }}
</div>
</body>
and here is my attempted edit of that patch:
@@ -7,5 +7,5 @@
<title>{{ page.title }}</title>
<link rel="stylesheet" href="/css/style.css">
</head>
- <body>
- <div class="content container">
+
+ <body class="container">
Git rejects this patch, saying:
Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]?
I don't get it though:
Both - and + start at line 7
Both - and + go on for 5 lines
When I look at the original file (below), and mentally attempt to apply my
suggested patch, it seems to make sense. What's wrong?
For reference, here's the whole original file:
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6 <meta name="viewport" content="width=device-width,
initial-scale=1.0">
7 <title>{{ page.title }}</title>
8 <link rel="stylesheet" href="/css/style.css">
9 </head>
10 <body>
11 <div class="content container">
12 {{ content }}
13 </div>
14 </body>
15 </html>
Also, here is a patch I wrote that Git doesn't complain about:
@@ -7,8 +7,9 @@
<title>{{ page.title }}</title>
<link rel="stylesheet" href="/css/style.css">
</head>
- <body>
- <div class="content container">
+
+ <body class="container">
+ <div class="content">
{{ content }}
</div>
</body>
It's actually a better patch in some ways, but I'd like to understand why
Git doesn't like my first approach.

No comments:

Post a Comment