سؤال

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
هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

As usual.. a quick solution after I post the question to Stack.

I had tried two solutions that I found after searching for how to fix line endings in Mac OSX.

  1. dos2Unix
  2. cat file | col -b > file2

Neither of these worked.

Finally, I tried 'perl -pi -e 's/\r/\n/g' ' Which did the trick.

To be fair, while this was appearing in git diff, it wasn't a git problem, it was simply a Mac/Windows line ending issue.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top