Eclipse 和 Windows 换行符
当我的桌面崩溃时,我不得不将 Eclipse 工作区从 Linux 移动到 Windows。一周后我把它复制回Linux,愉快地编码,提交给CVS。唉,Windows 换行符已经污染了许多文件,因此 CVS diff 会转储整个文件,即使我更改了一两行!
我可以编写一个脚本,但我想知道它是否会弄乱我的 Eclipse 项目文件。
I had to move my Eclipse workspace from Linux to Windows when my desktop crashed. A week later I copy it back to Linux, code happily, commit to CVS. And alas, windows newlines have polluted many files, so CVS diff dumps the entire file, even when I changed a line or two!
I could cook up a script, but I am wondering if it will mess up my Eclipse project files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正如此处和此处:
提示:您可以通过以下方式轻松转换现有文件在 Package Explorer 中选择 then,然后转到菜单项
File : Convert Line Delimiters to : Unix
As mentioned here and here:
Tip: You can easily convert existing file by selecting then in the Package Explorer, and then going to the menu entry
File : Convert Line Delimiters to : Unix
即使更改了一行,我也有相同的 Eclipse 污染文件。
解决办法:Eclipse git设置->添加条目:
密钥:core.autocrlf
值: true
I had the same, eclipse polluted files even with one line change.
Solution: Eclipse git settings -> Add Entry:
Key: core.autocrlf
Values: true
有一个方便的 bash 实用程序 - dos2unix - 它是 DOS/MAC 到 UNIX 文本文件格式转换器,如果您的发行版上尚未安装,应该可以通过包管理器轻松安装。 dos2unix 手册页
There is a handy bash utility -
dos2unix
- which is a DOS/MAC to UNIX text file format converter, that if not already installed on your distro, should be able to be easily installed via a package manager. dos2unix man page除了 另一个答案中提到的 Eclipse 解决方案和工具之外,请考虑 翻转。它可以在正常换行符和 Windows 换行符之间以任意方式“翻转”,并且可以做一些很好的事情,例如保留文件的时间戳和其他统计信息。
您可以像这样使用它来解决您的问题:(
我放入了一个子句来忽略您的 .git 目录,以防您使用 git,但由于 Flip 默认情况下会忽略二进制文件,因此您可能不需要这个。)
In addition to the Eclipse solutions and the tool mentioned in another answer, consider flip. It can 'flip' either way between normal and Windows linebreaks, and does nice things like preserve the file's timestamp and other stats.
You can use it like this to solve your problem:
(I put in a clause to ignore your .git directory, in case you use git, but since flip ignores binary files by default, you mightn't need this.)
你可以尝试一下。问题在于,当给定新行时,Windows 会插入回车符和换行符。 Unix 系统只插入换行符。因此,额外的回车符可能是您的日食与换行符混淆的原因。
从项目中获取一两个文件并进行转换。您可以使用 Notepad++ 来执行此操作。只需打开文件,转到“格式”->“转换为 Unix”(当您使用 Windows 时)。
在 Linux 中只需在命令行上尝试一下:
You could give it a try. The problem is that Windows inserts a carriage return as well as a line feed when given a new line. Unix-systems just insert a line feed. So the extra carriage return character could be the reason why your eclipse messes up with the newlines.
Grab one or two files from your project and convert them. You could use Notepad++ to do so. Just open the file, go to Format->Convert to Unix (when you are using windows).
In Linux just try this on a command line:
要从所有子目录中的 CVS/* 文件中递归删除回车符 (
\r
),请在 unix shell 中运行以下命令:To recursively remove the carriage returns (
\r
) from the CVS/* files in all child directories, run the following in a unix shell: