简体   繁体   English

git clone后如何修复Windows行尾

[英]How to fix windows line endings after git clone

I have cloned a repository from github on a Windows 7 box, and made some of changes I would hate to lose. 我已经在Windows 7的盒子上从github克隆了一个存储库,并做了一些我不想丢失的更改。 However, all my file have wrong line endings, \\n instead of \\r\\n. 但是,我所有文件的行尾都有错误的\\ n而不是\\ r \\ n。

How should I fix it? 我应该如何解决?

I think I should clone my repo again with correct line endings, and move over my changes manually. 我认为我应该再次使用正确的行尾克隆我的仓库,然后手动移动我的更改。

How do I clone it properly, so that all line ending are \\r\\n? 如何正确克隆它,以便所有行尾都为\\ r \\ n?

Are there any better suggestions? 有什么更好的建议吗?

You can't clone the repository with a different style of line endings. 您不能使用其他样式的行尾克隆存储库。 The data in the repository is what it is. 存储库中的数据就是它的内容。 What you can do is tell git how you want to handle the line endings when checking in or out. 您可以做的是告诉git在签入或签出时要如何处理行尾。 The link that birryree pointed out in the comments is a good source. birryree在评论中指出的链接是一个很好的来源。 There is also Github's help page on it. 上面还有Github的帮助页面。

Depending on what you are editing, you can also use a Windows text editor that doesn't require crlf, like notepad++ . 根据您要编辑的内容,还可以使用不需要crlf的Windows文本编辑器,例如notepad ++ You can change the line endings that notepad++ uses by default in settings->preferences->New Document/Default Directory 您可以在settings->preferences->New Document/Default Directory更改notepad ++默认使用的行尾

To add from Charles' comment, you can also convert line endings to unix or windows style in notepad++. 要从Charles的注释中添加内容,您还可以在记事本++中将行尾转换为Unix或Windows样式。 You do this by going to edit->EOL Conversion 您可以通过edit->EOL Conversion

Another way is to run the dos2unix win32 utility found here . 另一种方法是运行在此处找到的dos2unix win32实用程序。

Info: dos2unix.exe converts MS-DOS text files to Unix format, by stripping any CR or end-of-file ( Ctrl - Z ) characters from the data. 信息: dos2unix.exe通过从数据中剥离任何CR或文件结尾( Ctrl - Z )字符,将MS-DOS文本文件转换为Unix格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM