# Whitespace on commit

3 messages from 2008-03-13 to 2008-03-13. Participants: Kenneth P. Turvey, Junio C Hamano, Andreas Ericsson.
Thread: https://gitlist.dev/t/12661

## Kenneth P. Turvey, 2008-03-13 03:38

Subject: Whitespace on commit
Message-ID: <fra7ji$7p9$1@ger.gmane.org>
URL: https://gitlist.dev/e/fra7ji%247p9%241%40ger.gmane.org

```
I keep getting annoying errors when I try to commit.  Git complains that I
have whitespace in the wrong places.  

This is fine.. I even like it.  What I don't like is having to change this
stuff manually.  Is there anyway to tell git to just fix the stuff and do
the commit?  

I've tried setting

apply.whitespace = fix 

in my .gitconfig, but that doesn't seem to help when doing commits.  Is
there another way to handle this? 

Thanks!

-- 
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>

```

## Junio C Hamano, 2008-03-13 03:52

Subject: Re: Whitespace on commit
Message-ID: <7viqzr1dsp.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7viqzr1dsp.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <fra7ji$7p9$1@ger.gmane.org>

```
"Kenneth P. Turvey" <kt-usenet@squeakydolphin.com> writes:

> I keep getting annoying errors when I try to commit.  Git complains that I
> have whitespace in the wrong places.  
>
> This is fine.. I even like it.  What I don't like is having to change this
> stuff manually.  Is there anyway to tell git to just fix the stuff and do
> the commit?  
>
> I've tried setting
>
> apply.whitespace = fix 
>
> in my .gitconfig, but that doesn't seem to help when doing commits.

Yeah, that is to protect yourself from whitespace mess _other people_
threw at you in a patch form.

You can ask git to fix your own stuff up, by pretending that you are that
other person who made the mess, by doing:

	git diff HEAD >P.diff
        git reset --hard HEAD
        git apply --index --whitespace=fix P.diff

```

## Andreas Ericsson, 2008-03-13 07:34

Subject: Re: Whitespace on commit
Message-ID: <47D8D910.5060901@op5.se>
URL: https://gitlist.dev/e/47D8D910.5060901%40op5.se
In-Reply-To: <7viqzr1dsp.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano wrote:
> "Kenneth P. Turvey" <kt-usenet@squeakydolphin.com> writes:
> 
>> I keep getting annoying errors when I try to commit.  Git complains that I
>> have whitespace in the wrong places.  
>>
>> This is fine.. I even like it.  What I don't like is having to change this
>> stuff manually.  Is there anyway to tell git to just fix the stuff and do
>> the commit?  
>>
>> I've tried setting
>>
>> apply.whitespace = fix 
>>
>> in my .gitconfig, but that doesn't seem to help when doing commits.
> 
> Yeah, that is to protect yourself from whitespace mess _other people_
> threw at you in a patch form.
> 
> You can ask git to fix your own stuff up, by pretending that you are that
> other person who made the mess, by doing:
> 
> 	git diff HEAD >P.diff
>         git reset --hard HEAD
>         git apply --index --whitespace=fix P.diff
> 

I have exactly that (except my P.diff sits in /tmp under a different name)
as an alias named wsfix. Here's how to make one of your own, Kenneth:

git config --global alias wsfix '!git diff HEAD >P.diff && git reset --hard HEAD && git apply --index --whitespace=fix P.diff && rm -f P.diff'

Note that there are no newlines in the above command. When you get the whitespace
warnings, just run "git wsfix" and you'll be good to go.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

```
