Eclipse 和 Windows 换行符

发布于 2024-08-14 12:30:38 字数 180 浏览 5 评论 0原文

当我的桌面崩溃时,我不得不将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

ゞ花落谁相伴 2024-08-21 12:30:38

正如此处此处

将文件编码设置为 UTF-8 并将新文件的行结尾设置为 Unix,以便文本文件以非 Windows 操作系统特定的格式保存,并且最容易在异构之间共享开发者桌面:

  • 导航至工作区偏好设置(常规:工作区)
  • 将文本文件编码更改为 UTF-8
  • 将新文本文件行分隔符更改为“其他”并从选择列表中选择 Unix

替代文字

  • 注意:要转换现有文件的行结尾,请在 Eclipse 中打开该文件并选择文件:将行分隔符转换为:Unix

提示:您可以通过以下方式轻松转换现有文件在 Package Explorer 中选择 then,然后转到菜单项 File : Convert Line Delimiters to : Unix

As mentioned here and here:

Set file encoding to UTF-8 and line-endings for new files to Unix, so that text files are saved in a format that is not specific to the Windows OS and most easily shared across heterogeneous developer desktops:

  • Navigate to the Workspace preferences (General:Workspace)
  • Change the Text File Encoding to UTF-8
  • Change the New Text File Line Delimiter to Other and choose Unix from the pick-list

alt text

  • Note: to convert the line endings of an existing file, open the file in Eclipse and choose File : Convert Line Delimiters to : Unix

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

紫竹語嫣☆ 2024-08-21 12:30:38

即使更改了一行,我也有相同的 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

enter image description here

enter image description here

意犹 2024-08-21 12:30:38

有一个方便的 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

潜移默化 2024-08-21 12:30:38

除了 另一个答案中提到的 Eclipse 解决方案和工具之外,请考虑 翻转。它可以在正常换行符和 Windows 换行符之间以任意方式“翻转”,并且可以做一些很好的事情,例如保留文件的时间戳和其他统计信息。

您可以像这样使用它来解决您的问题:(

find . -type f -not -path './.git/*' -exec flip -u {} \;

我放入了一个子句来忽略您的 .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:

find . -type f -not -path './.git/*' -exec flip -u {} \;

(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.)

掌心的温暖 2024-08-21 12:30:38

你可以尝试一下。问题在于,当给定新行时,Windows 会插入回车符和换行符。 Unix 系统只插入换行符。因此,额外的回车符可能是您的日食与换行符混淆的原因。

从项目中获取一两个文件并进行转换。您可以使用 Notepad++ 来执行此操作。只需打开文件,转到“格式”->“转换为 Unix”(当您使用 Windows 时)。

在 Linux 中只需在命令行上尝试一下:

sed 's/
"/`echo \\\r`/" yourfile.java > output.java

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:

sed 's/
"/`echo \\\r`/" yourfile.java > output.java
哆兒滾 2024-08-21 12:30:38

要从所有子目录中的 CVS/* 文件中递归删除回车符 (\r),请在 unix shell 中运行以下命令:

find ./ -wholename "\*CVS/[RE]\*" -exec dos2unix -q -o {} \;

To recursively remove the carriage returns (\r) from the CVS/* files in all child directories, run the following in a unix shell:

find ./ -wholename "\*CVS/[RE]\*" -exec dos2unix -q -o {} \;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文