If you are working on a Unix / Mac, then this error is because you have the incorrect line endings.
here are some steps to correct.
-
Set your line endings correctly, and have git manage how it handles them.
$ git config --global core.autocrlf input
Then, in your directory, you are going to basically convert all of the files.
-
Now you have to run the following
$ find ./ -type f -exec dos2unix {} \;
This will cycle through all of your files, and convert them. This will solve the error. Add your changes. Commit them, and you should be good to go.
For those of you who got "find: ‘dos2unix’: No such file or directory" error: sudo apt install dos2unix – RealMan Jul 26 '17 at 14:59
-
Note that that find command may be excessive... this point is arguable; it may well be fine, but it may be overkill in some situations. Another possible route (for step 2 in this answer) is
git rm -r --cached .
followed bygit reset --hard HEAD
... which is likely faster (if nothing else, it won't run dos2unix on files in the.git
housekeeping directory!)... This has potential gotchas as well (probably quite fine if you're running from a "clean" checkout, though), but thought I'd at least mention it. – lindes Jul 13 '19 at 0:42