Git error: "fatal: corrupt patch at line 36"
git error: could not read
error: failed to push some refs to
I have a Java file that ends like this:
And I mistakenly erased the newline at the end some time ago, but it was fine just until today when I got an error message from Git-GUI when commiting
fatal: corrupt patch at line 36
I tried adding the missing newline, but Git seems not to be able to handle it right:
Before adding newline:
} } \ No newline at end of file
After adding newline:
} -} \ No newline at end of file +}
And it still gives me that error.
I tried reverting changes and adding only the newline without other changes to the file, but it didn't help either.
EDIT: Adding two or even three newlines doesn't help too.
EDIT2: This error occurs only when commiting lines within the last hunk.
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)
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 <---
Git error - Fatal: Not a git repository and how to fix it, Check with `ls`. Initialized your repository with `git init` or by cloning an existing repo. Usually, this is enough to fix the error� The error “ You need to resolve your current index first ” occurs in Git and means that there is a merge conflict and unless you resolve the conflict, you will not be allowed to checkout to another branch. This error message also signifies that a merge failed or there are conflicts with the files.
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.
@@ -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.
Git Tutorial: 10 Common Git Problems and How to Fix Them , 10 most common Git tricks you should know about! Sometimes the best way to get a feel for a problem is diving in and playing around with the code. Unfortunately, the changes made� The error `fatal: remote origin already exists` is caused when you attempt to create a link to a remote repository called “origin” when a remote link with that name is already configured.
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.
Oh Shit, Git!?!, On a "broken link" message, you could follow the GitFaq recommendations: back up all your state so� git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master There is no need to pull --rebase. Note: git reset --mixed origin/master can also be written git reset origin/master, since the --mixed option is the default one when using git reset.
I just had a similar problem (probably equal due to the workings of git gui) to this, which may be useful to anyone having it as well.
When patching my pom.xml via
git add -e pom.xml, the patch was the following.
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 the Mockito-dependency. If I just remove the lines itself, it always gives me an error reporting to 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 after
The solution was to simply remove the whole trunk, so everything from the @@-line downwards, and it worked immediately.
I hope this helps.
How to deal with Git "Could not read" error, I spelled that last commit message wrong. After a good few hours of coding, it's easy for a spelling error� The error message “ Your local changes to the following files will be overwritten by merge ” occurs in Git version control mechanism. This error occurs if you have modified a file which also has modifications in the remote repository. Git Error: Your local changes to the following files will be overwritten by merge
I had this same issue, and finally figured out what it was. Some of my lines were indented with tabs instead of spaces. After changing all my indentation to spaces, it worked.
Git happens! 6 Common Git mistakes and how to fix them, This leads Git to be unaware of your local history and will, therefore, cause it to throw this error when you try to push to� In case of a clone with multiple remotes, the git checkout Branch does not work. With multiple remotes just the Branch name is ambiguous and requires the specification of remote/branch. The command git checkout -b branch remote/branch works in that scenario. – Umair Ishaq Jul 15 '14 at 0:57
Troubleshooting Git, Returns error code 1 if no value is found. --global. For writing options: write to global ~/.gitconfig file rather than the� The most probable reason for this error is that all the files are untracked and have not been added. git add --all in case you wish to add all the files Or you can selectively add files. Then git commit -m "Initial comment", git push origin master. This will surely work. – Bhanu Pratap Singh May 20 '15 at 7:57
The “fatal: refusing to merge unrelated histories” Git error, git remote -v . Step 6 : git push . Got the following error message : fatal: The current branch master has no� Changing the name associated with your Git commits using git config will only affect future commits and will not change the name used for past commits. Setting your Git username for every repository on your computer. Open Terminal Terminal Git Bash. Set a Git username: $ git config --global user.name "Mona Lisa"
git-config Documentation, The "fatal: refusing to merge unrelated histories" error It is worth pointing out a little bit about how Git works and specifically and how it tracks each repository’s individual history. When a $git init command is executed to create a new Git repository, Git will create a directory with the extension.git.
- Do you mean "corrupt path" or "corrupt patch"?
- @Useless "corrupt patch". Edited it.
- Likely the same issue as here.
- @mart1n But no solution.
- Note: I implicitly assume you are committing from command-line. If you are committing from
git guiand didn't try it from command-line, you should mention it and try command-line and report whether it works.
- That will mention that the patch does not apply, not that it is corrupt.
- Wow as if adding an extra line with just a space made my patch apply
- @Jake88 Than is because of first character is special in patch: ' ' (space) leave line intact, '+' this line is new, '-' this line will be removed, '\' No newline at end of file. Some editors remove alone spaces at line, but this is critical for patches
- Good info, thanks! You can accept your own answer, btw, since it solved the problem.
- It did not answer where were problem and why was solved