views:

1266

answers:

2

Whitespace, it turns out, has ended up being a horrible pain for me while using git.

git config apply.whitespace=strip seems to highten your chances of getting conflicts (as you strip unneeded whitespace and then other collaborators see the stripped whitespace as a change to their commits?)

I've tried a few other configurations for apply.whitespace in the past, and maybe one of the other configs solves this, or maybe there's other settings to deal with whitespace that I just haven't come across, but I haven't yet found a clear way to get where I want to be.

Where I want to be: I never want to have another conflict on whitespace. If another committer alters whitespace, or I alter whitespace and then have to merge against my own conflicts, i really don't want to know about it. If someone changes my code from K&R style to One True Brace style by changing whitespace, I'd prefer git paying no attention over having to see conflicts about it.

So... ...is there any way that I can configure git to do that?

If it makes any difference, here's my git version, and my current config:

tchalvak:~/ninjawars$ git --version
git version 1.6.0.4

tchalvak:~/ninjawars$
git config --list
color.branch=auto
color.diff=auto
color.status=auto
color.branch.current=yellow reverse
color.branch.local=yellow
color.branch.remote=green
color.diff.meta=yellow bold
color.diff.frag=magenta bold
color.diff.old=red bold
color.diff.new=green bold
color.status.added=yellow
color.status.changed=green
color.status.untracked=cyan
gui.recentrepo=/home/tchalvak/zd/htdocs/cms
apply.whitespace=strip
user.name=****
user.email=****
alias.co=checkout
github.user=tchalvak
github.token=****
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
[email protected]:tchalvak/ninjawars.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
A: 

The real problem here is that you are working with people who can't agree on a coding style.

Eric Anderson
I don't think that that's the root of the problem. It is more apt to say that I'm working with multiple -editors- that don't agree on a whitespace style, which is a much harder problem for me to solve. I work with "meld" for viewing and dealing with colorized conflicts, the gedit gnome text editor, vi, and github's web commits editor. And that's just self-conflicts, I have no idea what people I'm collaborating with are using. Regardless, conflicts on whitespace sap my time for little benefit, what the -source- is doesn't matter, I just need to be able to ignore them as smoothly as possible.
Tchalvak
+6  A: 

Git1.6.0.4 seems a bit old, especially if you consider that:

  • in 1.6.3.4, "git apply --whitespace=fix" did not fix trailing whitespace on an incomplete line
  • in 1.6.3.2, "whitespace" attribute that is set was meant to detect all errors known to git, but it told git to ignore trailing carriage-returns.

Could you try with Git1.6.4.1, and rather than setting a global config, set an attribute on the files you want a special whitespace handle, like this article describes.

In a given directory, create a .gitattributes file.

* -whitespace

which will ignore any 'whitespace' errors.

Now that will not prevent any conflict due to lack of consistency but that may be worth trying.

VonC
*nods* Yeah, I've been using the git binary in the ubuntu repositories, but perhaps it's time that I got a bit closer to the most recent versions, maybe that'll help with the issue.I'll also see what difference the .gitattributes setting makes on the situation.
Tchalvak
'lright, I've (happily) added the launchpad ppa for the latest stable version of git in ubuntu, hopefully that'll fix things up.
Tchalvak