Home > programming > Git(Hub) and Mac Line Endings

Git(Hub) and Mac Line Endings

During my first project created in X-Code which I wanted to store in public GitHub repository I encountered issue with showing content of my source files on GitHub web page. After contacting with GitHub support (btw, they answer really fast and are helpful) they pointed out my line endings.

Quick recon brought surpassing results. I realized that even modifying single line of code in the source file, git shows modification in the whole file, because it sees this file as a single line (Mac line endings was shown as ^M). Why I didn’t noticed it earlier? Don’t know. I’m a noobie on Mac.

The first solution for GitHub web page was to set following git config attribute:

git config --global core.autocrlf input

It should commit files with Unix line endings. I know it works in Windows, but somehow it hadn’t worked for me on my Mac. Creating new project from scratch didn’t help either and even if it would help for files committed to the repository, my local git problem is still not resolved.

The solution was to set in X-Code configuration (Command + “,”) line ending for new and existing files to Unix (LF) instead of Mac (CR):

It solved issues with newly created files, but old ones was still invalid (maybe someone will explain me how this “For existing files” option works). Following command executed on all current files, which simple swaps line endings, solved the issue:

tr '\r' '\n' < <old_file> > <new_file>
Categories: programming Tags: ,
  1. nazgob
    December 8, 2010 at 23:24

    awesome, i thought it has to be related to xcode couse vim by default is putting proper line endings.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: