Skip to main content
added 1 character in body
Source Link
gitaarik
  • 45.3k
  • 12
  • 99
  • 109

In my case I was working on a project which was developed in Windows and I used OS XLinux. When I changed some code, I saw ^M at the end of the lines I added in git diff. I think the ^M were showing up because they were different line endings than the rest of the file. Because the rest of the file was developed in Windows it used CRLF line endings, and in OS XLinux it uses LF line endings.

In my case I was working on a project which was developed in Windows and I used OS X. When I changed some code, I saw ^M at the end of the lines I added in git diff. I think the ^M were showing up because they were different line endings than the rest of the file. Because the rest of the file was developed in Windows it used CRLF line endings, and in OS X it uses LF line endings.

In my case I was working on a project which was developed in Windows and I used Linux. When I changed some code, I saw ^M at the end of the lines I added in git diff. I think the ^M were showing up because they were different line endings than the rest of the file. Because the rest of the file was developed in Windows it used CRLF line endings, and in Linux it uses LF line endings.

added 55 characters in body
Source Link
gitaarik
  • 45.3k
  • 12
  • 99
  • 109

In my case I was working on a project which was developed in Windows and I used OS X. When I changed some code, I saw ^M at the end of the lines I added in git diff. I think the ^M were showing up because they were different line endings than the rest of the file. Because the rest of the file was developed in Windows it used CRCRLF line endings, and in OS X it uses LF line endings.

If you go for this option, you should however fix the current files (because they're still using the CRCRLF line endings). I did this by following these steps:

  1. Remove all files from the repository, but not from your filesystem.

     git rm --cached -r .
    
  2. Add a .gitattributes.gitattributes file that enforces certain files to use a LF as line endings. Put this in the file:

     *.ext texttext=auto eol=crlfeol=lf
    

    Replace .ext with the file extensions you want to match.

  3. Add all the files again.

     git add .
    

    This will show messages like this:

     warning: CRLF will be replaced by LF in <filename>.
     The file will have its original line endings in your working directory.
    
  4. You could remove the .gitattributes file unless you have stubborn Windows users that don't want to use the "Checkout Windows-style, commit Unix-style line endings" option.

  5. Commit and push it all.

  6. Remove and checkout the applicable files on all the systems where they're used. On the Windows systems, make sure they now use the "Checkout Windows-style, commit Unix-style line endings" option. You should also do this on the system where you executed these tasks because when you added the files git said:

     The file will have its original line endings in your working directory.
    

    You can do something like this to remove the files:

     git ls | grep ".ext$" | xargs rm -f
    

    And then this to get them back with the correct line endings:

     git ls | grep ".ext$" | xargs git checkout
    

    Of course replacingReplacing .ext with the extensionfile extensions you want to match.

In my case I was working on a project which was developed in Windows and I used OS X. When I changed some code, I saw ^M at the end of the lines I added in git diff. I think the ^M were showing up because they were different line endings than the rest of the file. Because the rest of the file was developed in Windows it used CR line endings, and in OS X it uses LF line endings.

If you go for this option, you should however fix the current files (because they're still using the CR line endings). I did this by following these steps:

  1. Remove all files from the repository, but not from your filesystem.

     git rm --cached -r .
    
  2. Add a .gitattributes file that enforces certain files to use a LF as line endings. Put this in the file:

     *.ext text eol=crlf
    

    Replace .ext with the file extensions you want to match.

  3. Add all the files again.

     git add .
    

    This will show messages like this:

     warning: CRLF will be replaced by LF in <filename>.
     The file will have its original line endings in your working directory.
    
  4. You could remove the .gitattributes file unless you have stubborn Windows users that don't want to use the "Checkout Windows-style, commit Unix-style line endings" option.

  5. Commit and push it all.

  6. Remove and checkout the applicable files on all the systems where they're used. On the Windows systems, make sure they now use the "Checkout Windows-style, commit Unix-style line endings" option. You should also do this on the system where you executed these tasks because when you added the files git said:

     The file will have its original line endings in your working directory.
    

    You can do something like this to remove the files:

     git ls | grep ".ext$" | xargs rm -f
    

    And then this to get them back with the correct line endings:

     git ls | grep ".ext$" | xargs git checkout
    

    Of course replacing .ext with the extension you want.

In my case I was working on a project which was developed in Windows and I used OS X. When I changed some code, I saw ^M at the end of the lines I added in git diff. I think the ^M were showing up because they were different line endings than the rest of the file. Because the rest of the file was developed in Windows it used CRLF line endings, and in OS X it uses LF line endings.

If you go for this option, you should however fix the current files (because they're still using the CRLF line endings). I did this by following these steps:

  1. Remove all files from the repository, but not from your filesystem.

     git rm --cached -r .
    
  2. Add a .gitattributes file that enforces certain files to use a LF as line endings. Put this in the file:

     * text=auto eol=lf
    
  3. Add all the files again.

     git add .
    

    This will show messages like this:

     warning: CRLF will be replaced by LF in <filename>.
     The file will have its original line endings in your working directory.
    
  4. You could remove the .gitattributes file unless you have stubborn Windows users that don't want to use the "Checkout Windows-style, commit Unix-style line endings" option.

  5. Commit and push it all.

  6. Remove and checkout the applicable files on all the systems where they're used. On the Windows systems, make sure they now use the "Checkout Windows-style, commit Unix-style line endings" option. You should also do this on the system where you executed these tasks because when you added the files git said:

     The file will have its original line endings in your working directory.
    

    You can do something like this to remove the files:

     git ls | grep ".ext$" | xargs rm -f
    

    And then this to get them back with the correct line endings:

     git ls | grep ".ext$" | xargs git checkout
    

    Replacing .ext with the file extensions you want to match.

Fix bad grammar
Source Link
RJFalconer
  • 11.5k
  • 5
  • 52
  • 67

You can have the Windows users reinstall git and use the "Checkout Windows-style, commit Unix-style line endings" option. This is what I would prefer, because I see Windows as an exception in it'sits line ending characters and Windows fixes it'sits own issue this way.

You can have the Windows users reinstall git and use the "Checkout Windows-style, commit Unix-style line endings" option. This is what I would prefer, because I see Windows as an exception in it's line ending characters and Windows fixes it's own issue this way.

You can have the Windows users reinstall git and use the "Checkout Windows-style, commit Unix-style line endings" option. This is what I would prefer, because I see Windows as an exception in its line ending characters and Windows fixes its own issue this way.

added 11 characters in body
Source Link
gitaarik
  • 45.3k
  • 12
  • 99
  • 109
Loading
added 112 characters in body
Source Link
gitaarik
  • 45.3k
  • 12
  • 99
  • 109
Loading
added 31 characters in body
Source Link
gitaarik
  • 45.3k
  • 12
  • 99
  • 109
Loading
Source Link
gitaarik
  • 45.3k
  • 12
  • 99
  • 109
Loading