'git apply' failed with code 1: trailing whitespace in SourceTree

kramer65 picture kramer65 · Sep 10, 2015 · Viewed 9.2k times · Source

I'm using SourceTree for easy code reviewing before committing. Within SourceTree I often stage and commit only part of the lines which I changed in a document.

A couple days ago I received a piece of code from a programmer working on Windows, which caused some trouble with line endings. If I remember correctly, I then set core.autocrlf to true, which fixed the issues with the windows file. Since that moment however, I'm having major issues in another repo I'm working on. If I want to stage only part of a file in SourceTree I now get a massive error saying git apply' failed with code 1: [/a/long/path/here] trailing whitespace in SourceTree. So I figured I needed to set core.autocrlf back to what it was, which I "assumed" to be ("mother of all.. etc") false (I never messed with core.autocrlf before). So I set it to false which suddenly makes all files on which I change only one letter to be marked as having changed ALL lines in the file, which is obviously a major hassle during code review.

So I searched around and I found some examples of solutions here on SO, but that all uses adding extra parameters to git add and doing all kinds of weird stuff. Next to the fact that I don't think I can insert custom commands in the GUI of SourceTree I mostly wondered; How did it get so messy? And most importantly can't I just go back to how it was (whatever that was) instead of having to issue extra command everytime that I want to stage and commit?

Please note; I'm not afraid of the command line, I work in it pretty much the whole day. But I just like doing code reviews in a GUI such as SourceTree.

Any tip which helps me get things back to normal would greatly help me out!

Answer

Lee Richardson picture Lee Richardson · Feb 13, 2018

Set "Ignore whitespace". See screenshot:

enter image description here