Search code examples
windowsmacosline-endings

Normalize line endings


Trying to get line-endings cleaned up. I have a file in Git (Mostly edited in Eclipse on Windows and Mac OSX) The line endings are messed up; you can see below how the file appears in a Git diff.

In every case that the file is viewed, or edited (cat, Eclipse, Emacs, Windows or OSX) the file appears fine. It's only the diff that shows this problem.

I've used the Git normalization advice here (http://git-scm.com/docs/gitattributes) and have tried to replace line-endings using various scripts with no luck.

Any thoughts on how I can fix this file (It's not the only in my source control for which this is happening. However, other files are fine, and I can't find a consistent pattern that helps me understand why).

--- a/src/main/java/com/pcs/Utils.java
+++ b/src/main/java/com/pcs/Utils.java
@@ -1 +1 @@
-package com.pcs;^M^M/*^M^M LABORATORY INFORMATION SYSTEM V1.0^M Copyright (C) 2001 by John 
\ No newline at end of file
+package com.pcs;^M^M/*^M LABORATORY INFORMATION SYSTEM V1.0^M

Solution

  • Single ^M characters (or \r) are Mac line breaks. You can remove them with 'mac2unix'. Dos2unix will not convert Mac line breaks. Mac2unix does not convert DOS line breaks.