Carina C. Zona bio photo

Carina C. Zona

Email Twitter LinkedIn

In an ideal world, you could check out any arbitrary commit and it's pass all tests, and have no bits of code trailing along that belong to another feature/issue. Line-by-line staging is how I first got religion where Git was concerned. Judicious use of it truly makes ideal commits feasible. Ahhh. Truly a Cool Git Trick.

But there's a bug. Maybe you've seen it. Periodically, seemingly at random, attempting to stage or unstage a line results in an patch error such as "Applying patch failed with return value 128. Error: fatal: corrupt patch at line 12". Don't believe it.

The bug originates with Git-Gui, which doesn't know how to stage a line when the file doesn't end with a trailing newline (EOF). It's been a known problem since at least 2010 and it's a bug that's still around today.

Add the trailing newline. Solved.

P.S. Want to learn about staging lines with Git? Check out "Splitting up commits the easy way" by Peter Savage. GitX(L) and SourceTree both support this workflow really well, and (ironically) are much nicer GUIs overall. SourceTree, by the way, doesn't show this bug. GitX(L) does. Bah humbug.