Git error: "fatal: corrupt patch at line 36"

Another potential issue, especially when editing using a regular text editor, is failing to deal with the numbers at the beginning of the hunk, which denote how many lines are in the old code and how many are in the new code, as well as where it starts in each. If the numbers don't match up, you get the fatal: corrupt patch at line x error.

For example, @@ -32,9 +54,15 @@ tells it to find the code to be replaced at line 32 and for the next 9 lines in the original file, but in the edited file to have fifteen lines starting at line 54. If you add or remove any lines, you'll have to edit those numbers as well.

While I haven't done any real research into it or ever used git gui, it's conceivable that, since lines which don't end in newlines aren't technically lines according to some standards, you'd need to change one or both of those numbers by one to get it to apply correctly.


This is happens when you edit '-' lines.
When you remove '-' and forget to add ' ' (space) instead of it

Open your patch and check that all lines you want to leave untouched are started with ' ' (space)

UPDATE

It is also possible that your editor has the option: "Delete spaces at the end of line". So, when you save the patch in your editor:

-Line with space at end <--- NOTICE: Here there is one space at the end
+Line with no space at end<--- Here there's no space

Your editor will remove trailing space and patch become like this:

-Line with space at end<--- Here no space. Patch will FAIL!!!
+Line with no space at end<--- Here no space also

This patch will FAIL because the origin file has no line:

-Line with space at end<---

instead it has:

-Line with space at end <--- 

UPD
Sometimes you want to remove - lines. You change it by whitespace which is trimmed. So this does not work (here is just wihitespace as first character):

 

To workaround this just add + line after it:

-
+

This patch will remove empty line and add it again

Tags:

Git

Git Gui