如何在 git clone 之后修复 Windows 行结尾
我在 Windows 7 机器上从 github 克隆了一个存储库,并做了一些我不想失去的更改。但是,我的所有文件都有错误的行结尾,\n 而不是 \r\n。
我应该如何修复它?
我想我应该用正确的行结尾再次克隆我的存储库,并手动移动我的更改。
如何正确克隆它,以便所有行结尾均为 \r\n?
还有更好的建议吗?
I have cloned a repository from github on a Windows 7 box, and made some of changes I would hate to lose. However, all my file have wrong line endings, \n instead of \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?
Are there any better suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法克隆具有不同行尾样式的存储库。存储库中的数据就是这样。你可以做的就是告诉 git 在签入或签出时你想要如何处理行结尾。 birriree 在评论中指出的 链接 是一个很好的来源。还有 Github 的帮助页面。
根据您要编辑的内容,您还可以使用不需要 crlf 的 Windows 文本编辑器,例如 notepad++< /a>.您可以在
设置->首选项->新文档/默认目录
中更改notepad++默认使用的行结束符要从Charles的注释中添加,您还可以将行结束符转换为unix或windows样式在记事本++中。您可以通过
edit->EOL Conversion
来完成此操作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. The link that birryree pointed out in the comments is a good source. There is also Github's help page on it.
Depending on what you are editing, you can also use a Windows text editor that doesn't require crlf, like notepad++. You can change the line endings that notepad++ uses by default in
settings->preferences->New Document/Default Directory
To add from Charles' comment, you can also convert line endings to unix or windows style in notepad++. You do this by going to
edit->EOL Conversion
另一种方法是运行 此处 找到的
dos2unix
win32 实用程序。信息:
dos2unix.exe
通过删除任何CR
或文件结尾 (Ctrl-< kbd>Z) 数据中的字符。Another way is to run the
dos2unix
win32 utility found here.Info:
dos2unix.exe
converts MS-DOS text files to Unix format, by stripping anyCR
or end-of-file (Ctrl-Z) characters from the data.