Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 866
kramer65 Avatar asked Sep 10 '15 16:09

kramer65


3 Answers

Set "Ignore whitespace". See screenshot:

enter image description here

like image 159
Lee Richardson Avatar answered Nov 20 '22 00:11

Lee Richardson


There is a discussion on Atlassian Community about this problem. The fix is to switch setting Show Whitespace to Ignore Whitespace.

like image 32
Mykola Avatar answered Nov 19 '22 23:11

Mykola


In your ~/.gitconfig, try adding the following section:

[apply]
    whitespace = nowarn

The full details of what this does are covered at https://git-scm.com/docs/git-apply

The options for apply.whitespace are (from the git-scm page):

  • "nowarn" turns off the trailing whitespace warning.
  • "warn" outputs warnings for a few such errors, but applies the patch as-is (default).
  • "fix" outputs warnings for a few such errors, and applies the patch after fixing them
  • "error" outputs warnings for a few such errors, and refuses to apply the patch.
  • "error-all" is similar to error but shows all errors.

Seems like the default for SourceTree under OS X is "error", at least with git 2.6.4. Or it may be interacting with our default of core.autocrlf = true

like image 1
tgharold Avatar answered Nov 20 '22 00:11

tgharold