{"id":10008407,"date":"2024-02-27T15:59:29","date_gmt":"2024-02-27T07:59:29","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008407"},"modified":"2024-02-27T15:59:29","modified_gmt":"2024-02-27T07:59:29","slug":"lf-will-be-replaced-by-crlf","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008407","title":{"rendered":"LF will be replaced by CRLF"},"content":{"rendered":"<h2>\u524d\u7f6e\u77e5\u8bc6<\/h2>\n<p><code>LF<\/code>\u4ee3\u8868<code>linux<\/code>\u98ce\u683c\u7684\u884c\u5c3e\u5b57\u7b26<code>\/n<\/code><br \/><code>CRLF<\/code>\u4ee3\u8868<code>windows<\/code>\u98ce\u683c\u7684\u884c\u5c3e\u5b57\u7b26<code>\/r\/n<\/code><\/p>\n<h2>\u5982\u4f55\u8bfb\u53d6\u5f53\u524dgit config core.autocrlf\u7684\u8bbe\u7f6e\uff1f<\/h2>\n<pre><code class=\"bash\">git config core.autocrlf<\/code><\/pre>\n<h2>\u53ef\u80fd\u7684\u503c\uff1f<\/h2>\n<ul>\n<li>true<\/li>\n<li>false<\/li>\n<li>input<\/li>\n<\/ul>\n<h2>true<\/h2>\n<p>\u63d0\u4ea4\u65f6\uff1a\u5c06CRLF\u8f6c\u6362\u4e3aLF<br \/>\u62c9\u53d6\u65f6\uff1a\u5c06LF\u8f6c\u6362\u4e3aCRLF<\/p>\n<h2>false<\/h2>\n<p>\u63d0\u4ea4\u65f6\uff1a\u4ec0\u4e48\u90fd\u4e0d\u505a<br \/>\u62c9\u53d6\u65f6\uff1a\u4ec0\u4e48\u90fd\u4e0d\u505a<\/p>\n<h2>input<\/h2>\n<p>\u63d0\u4ea4\u65f6\uff1a\u5c06CRLF\u8f6c\u6362\u4e3aLF<br \/>\u62c9\u53d6\u65f6\uff1a\u4ec0\u4e48\u90fd\u4e0d\u505a<\/p>\n<h2>windows\u7cfb\u7edf\u8be5\u600e\u4e48\u505a\uff1f<\/h2>\n<p><code>windows<\/code>\u4e0a\u7684\u6362\u884c\u662f\u4ee5<code>CRLF<\/code>\u7ed3\u5c3e\u7684\uff0c\u8fd9\u6761\u547d\u4ee4\u5f88\u5951\u5408\u3002<\/p>\n<pre><code class=\"bash\">git config core.autocrlf true<\/code><\/pre>\n<h2>linux\u7cfb\u7edf\u8be5\u600e\u4e48\u505a\uff1f<\/h2>\n<p><code>linux<\/code>\u4e0a\u7684\u6362\u884c\u662f\u4ee5<code>LF<\/code>\u7ed3\u5c3e\u7684\uff0c\u8fd9\u6761\u547d\u4ee4\u5f88\u5951\u5408\u3002<\/p>\n<pre><code class=\"bash\">git config core.autocrlf input<\/code><\/pre>\n<h2>\u9879\u76ee\u4e2d\u6709windows\u548clinux\u7684\u5f00\u53d1\u4eba\u5458\u8be5\u600e\u4e48\u505a\uff1f<\/h2>\n<p>\u4e00\u822c\u7684\u4ee3\u7801\u6258\u7ba1\u670d\u52a1\u5668\u90fd\u662f<code>linux<\/code>\u7cfb\u7edf\uff0c\u6240\u4ee5\u6211\u4eec\u7684\u76ee\u6807\u662f\u8fd9\u6837\uff1a<br \/>\u65e0\u8bba\u4f60\u7684\u5f00\u53d1\u4eba\u5458\u662f\u4ec0\u4e48\u7cfb\u7edf\uff0c\u4ee5\u4ec0\u4e48\u6362\u884c\u7ed3\u5c3e\uff0c\u5230\u4e86\u4ee3\u7801\u6258\u7ba1\u7cfb\u7edf\uff0c\u7edf\u4e00\u4ee5<code>linux<\/code>\u4e3a\u6807\u51c6\uff0c\u4e5f\u5c31\u662f<code>LF<\/code>\u7ed3\u5c3e\u3002<\/p>\n<p>\u8ba9<code>windows<\/code>\u7528\u6237\u8bbe\u7f6e<\/p>\n<pre><code class=\"bash\">git config core.autocrlf true<\/code><\/pre>\n<p>\u8ba9<code>linux<\/code>\u7528\u6237\u8bbe\u7f6e<\/p>\n<pre><code class=\"bash\">git config core.autocrlf input<\/code><\/pre>\n<p>\u4f46\u662f\uff0c\u4e0a\u8ff0\u7684\u64cd\u4f5c\u4e0d\u592a\u53ef\u63a7\uff0c\u6bd4\u5982\u9879\u76ee\u91cc\u9762\u6210\u5458\u6709\u5f88\u591a\uff0c\u6211\u4e0d\u53ef\u80fd\u6328\u4e2a\u53bb\u53ee\u5631\u5e76\u68c0\u67e5\u4ed6\u4eec\u7684\u8bbe\u7f6e\u3002\u6709\u6ca1\u6709\u66f4\u597d\u7684\u529e\u6cd5\u5462\uff1f<br \/>\u6709\uff0c\u501f\u52a9<code>.gitattributes<\/code><\/p>\n<p>\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e0b\u6dfb\u52a0\u4e00\u4e2a.gitattributes\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code>\/\/ .gitattributes\n* text eol=lf<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u914d\u7f6e\uff0c\u610f\u5473\u7740\u65e0\u8bba\u5728\u4ec0\u4e48\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u5f53\u4f60\u68c0\u51fa\u6587\u4ef6\u65f6\uff0c\u6240\u6709\u7684\u884c\u7ed3\u675f\u7b26\u90fd\u4f1a\u88ab\u8f6c\u6362\u4e3aLF\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u8fdb\u884c\u534f\u4f5c\u65f6\uff0c\u6587\u4ef6\u7684\u884c\u7ed3\u675f\u7b26\u59cb\u7ec8\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<h2>\u7591\u95ee<\/h2>\n<h3>\u7591\u95ee1\uff1a<\/h3>\n<pre><code class=\"bash\">git rm --cached -r .\ngit reset --hard<\/code><\/pre>\n<p>\u8fd9\u4e0d\u662f\u91cd\u7f6e<code>.gitignore<\/code>\u7528\u7684\u5417\uff1f\u8fd9\u91cc\u9700\u8981\u5417\uff1f<\/p>\n<h3>\u7591\u95ee2\uff1a<\/h3>\n<p>\u6dfb\u52a0.gitattributes\u540e\u9700\u8981\u6267\u884c\u8fd9\u4e2a\u64cd\u4f5c\u5417\uff1f<\/p>\n<pre><code>git add --renormalize .<\/code><\/pre>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044660555\">https:\/\/segmentfault.com\/a\/1190000044660555<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u7f6e\u77e5\u8bc6 LF\u4ee3\u8868linux\u98ce\u683c\u7684\u884c\u5c3e\u5b57\u7b26\/nCRLF\u4ee3\u8868windows\u98ce\u683c\u7684\u884c\u5c3e\u5b57\u7b26\/r\/n \u5982\u4f55\u8bfb\u53d6\u5f53\u524dg [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008407","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008407"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008407\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}