Not too long ago, I asked this question. I received an answer, but it did not solve the issue I was having, so I was advised to create a new question with more detail.
Just to reiterate, I am getting an error when trying to manually edit a hunk in the Git bash shell on Windows, when using git add -p (specifically, I press e when prompted by the interactive command). This opens an edit file for the hunk in Notepad++ (my default .txt editor). Even without making any changes to this file, I am given the error:
Your edited hunk does not apply
As a minimal example, I have created a repo, value of git config core.autocrlf is false (I've also tried the following with value set to true). I have a .txt file (foobar.txt), I write foo in it, and commit my changes. Then I change the contents of the file to:
foo bar and then close the file. I then do git add -p foobar, and am prompted (not sure why the diff didn't work out cleanly in this case, but it generally does work for me):
diff --git a/foobar b/foobar index 1910281..a907ec3 100644 --- a/foobar +++ b/foobar @@ -1 +1,2 @@ -foo \ No newline at end of file +foo +bar \ No newline at end of file Stage this hunk [y,n,q,a,d,/,e,?]? to which I answer e. Again, without making any changes I get the error:
error: patch failed: foobar:1 error: foobar: patch does not apply Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]? Of course, I have also tried making changes to the manual hunk edit file; for example, the edit file will initially look like:
# Manual hunk edit mode -- see bottom for a quick guide @@ -1 +1,2 @@ -foo \ No newline at end of file +foo +bar \ No newline at end of file # --- # To remove '-' lines, make them ' ' lines (context). # To remove '+' lines, delete them. # Lines starting with # will be removed. # # If the patch applies cleanly, the edited hunk will immediately be # marked for staging. If it does not apply cleanly, you will be given # an opportunity to edit again. If all lines of the hunk are removed, # then the edit is aborted and the hunk is left unchanged. A sample edit would be:
# Manual hunk edit mode -- see bottom for a quick guide @@ -1 +1,1 @@ -foo \ No newline at end of file +foo \ No newline at end of file # --- # To remove '-' lines, make them ' ' lines (context). # To remove '+' lines, delete them. # Lines starting with # will be removed. # # If the patch applies cleanly, the edited hunk will immediately be # marked for staging. If it does not apply cleanly, you will be given # an opportunity to edit again. If all lines of the hunk are removed, # then the edit is aborted and the hunk is left unchanged. Another interesting point is that I have a developer's release of Windows, which allows me to use "Bash on Ubuntu on Windows". Using git add -p through this utility, and then trying to manually edit hunks, will work... so my question is, why does it not work on Git bash shell for me...?