Use the git diff Command to Ignore Whitespaces in Git We use the git diff -w command to ignore all whitespace differences. It will ignore spaces at the beginning, middle, and end of lines. We use the git diff --ignore-space-at-eol command to ignore whitespace changes at the end of our lines.
The --ignore-trailing-space ( -Z ) option ignores white space at line end. Re: "-w or --ignore-all-space option does not ignore newline-related changes" So -w ignores all whitespace, except for the whitespace it doesn't ignore.
Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.
You could use git alias or bash alias if you are using shell-available OS.
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
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.
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
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.
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
.
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.
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:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With