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

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


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


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.


commit does not do anything with patches. It does not even do anything with their content. The commit only formats the tree and commit objects and adjusts the HEAD and the ref it points to. So it's not commit itself that gives this error.

It is not add either, because while it hashes the new file content, it operates on the new content and does not care about differences at all.

The only think that cares about differences is the default pre-commit hook that checks that you are not adding trailing whitespace and few similar problems. You can skip that check by calling git commit --no-verify. But you'd have to have enabled it in the first place and you'd probably know it.