Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line endings issue between Mac and Windows

Tags:

git

I have a MacBook and am running Windows in a Parallels VM. My development is primarily in Visual Studio, but I like to use Git with the Mac shell (just like it better than what is available for Windows).

When I do a git diff to determine what has changed between commits I am getting the proverbial line ending "changes" that make git think much more has changed than actually has.

I know this is an age old problem, and I have done a lot of research with varying suggestions from a lot of people, but I am not able to solve this issue. The most promising information was found in this SO Post but it didn't solve my issue.

Here are some relevant lines from my .gitconfig...

[core]
    autocrlf = false
    safecrlf = false

Also, I have a .gitattributes in the root of my repo that only contains...

* text eol=crlf

What can I do to make Git stop thinking line ending changes are real changes when performing a diff? Again, I am using a Mac shell to look at Windows files, so this might be part of my issue.

Thanks!

like image 815
John Livermore Avatar asked Feb 26 '13 15:02

John Livermore


People also ask

Does Macos use CRLF or LF?

Line Breaks in Windows, UNIX & Macintosh Text Files Windows, and DOS before it, uses a pair of CR and LF characters to terminate lines. UNIX (Including Linux and FreeBSD) uses an LF character only. OS X also uses a single LF character, but the classic Mac operating system used a single CR character for line breaks.

What line endings does Mac use?

MAC OS X seems to be using unix-like line endings (LF) instead of the old mac line endings (CR). However if you use VIM (the one that comes preinstalled, at least in my macbook), you might get a surprise and get your files with dos-like line endings (CRLF).

Why does Windows use different line endings?

The Multics operating system began development in 1964 and used LF alone as its newline. Multics used a device driver to translate this character to whatever sequence a printer needed (including extra padding characters), and the single byte was more convenient for programming.

Does Mac use \r or \n?

The Mac, by default, uses a single carriage return ( <CR> ), represented as \r . Unix, on the other hand, uses a single linefeed ( <LF> ), \n . Windows goes one step further and uses both, creating a ( <CRLF> ) combination, \r\n .


1 Answers

I alias gdiff to:

git diff -w origin/`git branch | sed --quiet "s/* \(.*\)/\1/p"`

but you can just do:

git diff -w
like image 110
Caseman Avatar answered Nov 15 '22 04:11

Caseman