Git error: "fatal: damaged patch on line 36"

I have a Java file that ends as follows:

} } 

And I mistakenly deleted a new line at the end some time ago, but that was fine only until today, when I received an error message from Git-GUI when committing

 fatal: corrupt patch at line 36 

I tried adding a missing newline line, but Git seems to be unable to handle it correctly:

Before adding a new line:

  } } \ No newline at end of file 

After adding a new line:

  } -} \ No newline at end of file +} 

And it still gives me this error.

I tried to revert the changes and add only a new line without any changes to the file, but that didn't help either.

EDIT: Adding two or even three lines of a new line does not help either.

EDIT2: This error only occurs when executing rows in the last column.

+8
source share
5 answers

Okay, sorry to not have verified it completely.

I tried adding and commenting as usual, but without Git-GUI using the command line, and it worked.

So, I recommend to everyone who has problems with Git-GUI not to do as I do and check it through the command line before publishing.

0
source

This happens when you edit the '-' lines.
When you delete the '-' and forget to add the '' (space) instead

Open your patch and make sure that all lines that you want to leave intact begin with '' (space)

UPDATE

It is also possible that your editor has the option: "Remove spaces at the end of the 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 no space 

Your editor will remove the trailing space and the patch will become:

 -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 source file does not have a line:

 -Line with space at end<--- 

instead it has:

 -Line with space at end <--- 
+9
source

commit does nothing with corrections. He does not even do anything with their content. The end only formats the tree and commits the objects and adjusts the HEAD and ref that it points to. Therefore, he does not fix himself, which gives this error.

This is also not add , because when it hashes a new file, it works with new content and does not care about the differences at all.

The only thing that worries about the differences is the default pre-commit hook, which checks that you are not adding trailing spaces and a few similar issues. You can skip this verification by calling git commit --no-verify . But you would have to turn it on first, and you probably know that.

+2
source

I had a similar problem (probably equal to the work of git gui), which can be useful for everyone who has it.

When fixing my pom.xml via git add -e pom.xml patch was as follows.

 diff --git a/pom.xml b/pom.xml index 3dba69a..a9c8ebb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,26 +1,48 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>adowrath</groupId> <artifactId>project-name</artifactId> <version>0.0.1</version> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> <build> <sourceDirectory>src/main/java</sourceDirectory> <testSourceDirectory>src/test/java</testSourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.7.9</version> + <executions> + <execution> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + <execution> + <id>report</id> + <phase>test</phase> + <goals> + <goal>report</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.16</version> <configuration> <includes> <include>**/Test*.java</include> <include>**/*Test.java</include> <include>**/*Tests.java</include> @@ -32,9 +54,15 @@ </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>2.5.5</version> + <scope>test</scope> + </dependency> </dependencies> </project> 

And I wanted to remove the last block with a Mockito dependency. If I just delete the lines, it always gives me an error message on line 64:

 fatal: corrupt patch at line 64 fatal: Could not apply '.git/ADD_EDIT.patch' 

Line 64 is the last line in the patch file, so the line is after <project> .

The solution was to simply delete the entire body, so everything from the line @@ is down, and it worked immediately.

Hope this helps.

0
source

I had the same problem and I finally realized what it was. Some of my lines were indented from tabs instead of spaces. After changing all my indentation to spaces, it worked.

0
source

Source: https://habr.com/ru/post/1496097/


All Articles