14

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!

Community
  • 1
  • 1
kramer65
  • 50,427
  • 120
  • 308
  • 488

4 Answers4

17

Set "Ignore whitespace". See screenshot:

enter image description here

Lee Richardson
  • 8,331
  • 6
  • 42
  • 65
11

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

Mykola
  • 435
  • 4
  • 17
1

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

tgharold
  • 721
  • 6
  • 15
1

Surprisingly, for me the solution was to do the exact opposite to the most upvoted answer, which was to switch from "Ignore Whitespace" to "Show Whitespace" as described in this answer.

Neuron
  • 5,141
  • 5
  • 38
  • 59