121

I could probably setup an alias, but it seems like I should be able to set this as an option in the config file, only I don't see anyway to do it.

I only want the --ignore-space-change when I'm doing diff, not when I'm doing apply or anything else. I'm trying to make the diff easier to understand by not cluttering it with with extraneous +/- lines that have no real changes on them.

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
boatcoder
  • 17,525
  • 18
  • 114
  • 178

6 Answers6

110

You could use git alias or bash alias if you are using shell-available OS.

  1. git alias : Run this command to add alias:

    git config --global alias.dfw 'diff --ignore-space-change'

    --ignore-space-change can be abbreviated to -w
    to apply the alias using: git dfw

  2. bash alias : Run this command to add bash alias:

    echo "alias gitdfw='git diff --ignore-space-change'">>~/.profile

    Open a new terminal and you can directly run gitdfw to achieve the same.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
yjqg6666
  • 1,209
  • 2
  • 8
  • 3
  • 10
    This should be the accepted answer, because it is actually useful with examples rather than 'go to this URL'. – DrStrangepork Feb 06 '15 at 03:59
  • 10
    According to the [current git documentation](https://git-scm.com/docs/git-diff), `-b` is the same as `--ignore-space-change`. It aligns with the Linux `diff` command, where `-w` means `--ignore-all-space`. It's an important distinction because, for example, the text `a b c` is considered the same as `abc` with the `-w` option; in code, this is unlikely to be what you want, so `-b` is a better option. – IpsRich Sep 08 '17 at 08:49
20

According to the Git Config manual, there's no such option. Your only option is to make an alias.

http://git-scm.com/docs/git-config

Dogbert
  • 212,659
  • 41
  • 396
  • 397
15

Old question (2011), but now there's a shortcut git diff -w which stands for --ignore-all-space

Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.

João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109
12

I'd agree with Dogbert's answer that it's probably best to just use an alias, but another option is to set the config option diff.external to a wrapper script that calls diff with -b.

Community
  • 1
  • 1
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
9

This doesn't answer your question exactly, but it's a way to achieve something similar for apply.

From man git-config:

 apply.whitespace
       Tells git apply how to handle whitespaces, in the same way
       as the --whitespace option. See git-apply(1).

So open up your ~/.gitconfig or ./.git/config/ and append

[apply]
   whitespace = nowarn

It might also not let you commit something that only changes whitespace, but I'm sure you can overrule that with some flags.

cigien
  • 57,834
  • 11
  • 73
  • 112
2

it would be great if this were possible with an option. but an alias works fairly well. here are the relevant lines from my .gitconfig:

[diff]
    tool = mydiff
[difftool "mydiff"]
    cmd = "colordiff -NuBbwi \"$LOCAL\" \"$REMOTE\" | less -R"
[difftool]
    prompt = false
[alias]
    dt = difftool

this assumes using colordiff, which i recommend, giving you an almost exact copy of what git diff would show, with two differences:

  1. the --- line in colordiff is colored differently than the same line in git diff (very minor issue)
  2. each file is shown one at a time (annoying issue -- anyone know a fix?)

here's my /etc/colordiffrc:

plain=off
newtext=green
oldtext=red
diffstuff=cyan
cvsstuff=red

Mac OS X 10.9.2, git version 1.8.5.2 (Apple Git-48)

(colordiff was obtained from brew)

Joseph Cheek
  • 554
  • 5
  • 11