Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"fatal: corrupt patch at line XX" when staging single line

Tags:

git

git-gui

I'm getting the following error when I'm trying to stage a single line or multiple lines using the git gui (right click -> stage lines for commit). It's not the first time it occure to me, and I've found others facing it.However I couldn't find how to solve it.

Did any one ever encountered this problem? is there something I can do (staging all the file is not a real solution)

Update: Here is a file which gives me the following error when I try to stage the deleted line.

@@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android"      android:src="@drawable/texture"     android:tileMode="repeat" -   android:dither="true"     > </bitmap> \ No newline at end of file 

Here is the error message:

fatal: corrupt patch at line 14 

strangely the following fine doesn't even have 14 line!? note ending file with a new line didn't solve the problem

like image 347
Kirill Kulakov Avatar asked Aug 27 '12 19:08

Kirill Kulakov


2 Answers

Apparently Git GUI requires that files end with a newline when staging individual lines.

I'm pretty sure that at at least one point in time, staging individual lines was ok even without a newline at the end of the file, but apparently that's no longer possible. Just ran into this problem myself, having newlines at the end of the file fixes it, and removing them causes it.

like image 117
Kyle Avatar answered Sep 21 '22 12:09

Kyle


Actually, this often happens when you edit '-' lines.
When you remove '-' and forget to add ' ' (space) instead of it

Or, by mistake, you add two spaces and you use 'tabs' as identation

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

I have saw that some people use --ignore-space-change --ignore-whitespace --whitespace=fix as workaround but this is another thing you must not mix into.

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

UPD

it also possible your editor has option: "Delete spaces at end line" So, when you in your editor save patch:

-Line with space at end <--- NOTICE: Here one space at the end +Line with no space at end<--- Here no space 

Your editor 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 origin file has no line:

-Line with space at end<--- 

it has:

-Line with space at end <---  

UPD2

So if in your patch in next line

android:tileMode="repeat" 

Your editor remove trainling space. Patch will FAIL

like image 35
Eugen Konkov Avatar answered Sep 20 '22 12:09

Eugen Konkov