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.githousekeeping 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
本文介绍了解决在Unix/Mac环境下使用Git时遇到的错误——不正确的行结束符的方法。通过设置正确的行结束符配置,并利用dos2unix工具批量转换文件,可以有效修复此错误,确保代码的一致性和Git的正常运行。
1万+

被折叠的 条评论
为什么被折叠?



