Configure git to handle line endings

Since Rest R Ant application is an open source project, we need to make sure git takes care of normalizing line endings. Here is a link that explains why we need to do this.

I added a .gitattributes file under root folder of project to instruct git to handle line endings during checkout and commit operations. Here is the content of my .gitattributes file:

Git Attributes

My entries in .gitattributes is telling git to do the following:

  1. On all text files, update end of line with lf (line feed) like unix way.
  2. Let git handle javascript files automatically.
  3. On all .bat and .cmd files replace eol with crlf (carriage return line feed) the windows way.
  4. All jar files, png, pdf files are considered binary, which means they wont
    be modified during checkout and commit operations.

If .gitattributes file is added during middle of a project, run the following command to correct all end of line on all files.

  • git add –renormalize .

–renormalize option applies “clean” process freshly to all tracked files to forcibly add them again to the index.

Leave a Reply

Your email address will not be published. Required fields are marked *