Wednesday, January 23, 2013

Netbeans 7.2.1 + Git "-/Modified" Phantoms

If you use Git and NetBeans with a project that's been developed under Windows, Linux and Mac, you're probably used to seeing this (ignore the green stuff):

Only one of those POMs were actually modified. If you diff them, nothing has changed. It can get much worse that just a few files, every file you open will potentially show up in here. From what I can tell, this seems to be related to line-endings. There are some config values you need to set, and you can go about this in at least two ways.

Per Project

Add the following to your <project>/.git/config file. You only need to do this once per Git project you checkout.
        eol = lf
        autocrlf = input


This is what I opted for, since I always want this functionality. I prefer predictability.
git config --global core.eol lf
git config --global core.autocrlf input

This seems to tell Git to leave line-endings during checkout/clone, and to use line feeds (\n) when committing.

You can read more about how Git converts line endings in the gitattributes(5) man page.

There's also a bug on NetBeans' bug tracker that says this has been fixed, but it's not in 7.2.1 which is the current release version.