[英]Prevent EOL normalization for CSV files
I have a source repository that is used both from Windows and Linux . 我有一个源代码存储库,可以在Windows和Linux上使用 。
I know that Git will automatically convert EOL to the local standard: \\r\\n on Windows and \\n on Linux. 我知道Git会自动将EOL转换为本地标准:Windows上的\\ r \\ n和Linux上的\\ n 。
This is not an issue for source files. 这不是源文件的问题。
But I have some CSV files that use a fixed format with a given EOL character ( \\r\\n ) which should not be changed, but Git converts them too, breaking some code. 但我有一些CSV文件使用固定格式和给定的EOL字符( \\ r \\ n ),不应该更改,但Git也会转换它们,破坏了一些代码。
I've tried to prevent EOL conversions for CSV files by creating a .gitattributes file at the root, next to the .gitignore file, with the following content: 我试图通过在.gitignore文件旁边的根目录创建一个.gitattributes文件来阻止CSV文件的EOL转换,其中包含以下内容:
*.csv -text
I've applied what I've understood from: http://git-scm.com/docs/gitattributes 我已经应用了我所理解的内容: http : //git-scm.com/docs/gitattributes
But Git is still converting \\r\\n to \\n on Linux. 但是Git仍然在Linux上将\\ r \\ n转换为\\ n 。
Should I play with another setting like auto.crlf? 我应该使用auto.crlf等其他设置吗?
Note that I have limited control of the Linux local repository as it is managed by the continuous integration server Jenkins . 请注意,我对Linux本地存储库的控制有限,因为它由持续集成服务器Jenkins管理 。
Thanks for any input. 感谢您的任何意见。
Please note that git uses LF as an internal representation of EOL. 请注意,git使用LF作为EOL的内部表示。
This means that in your case, the *.csv files has got changed when they were added/committed. 这意味着在您的情况下,* .csv文件在添加/提交时已更改。
So the solution goes roughly like this: 所以解决方案大致如下:
Actually, it can be all made in one commit, with the following commands: 实际上,它可以在一次提交中完成,使用以下命令:
### ... update .gitattributes
git rm --cached '*.csv'
### ... find -name '*.csv' -print0| xargs -0 unix2dos
git add '*.csv'
git add .gitattributes
git commit
Explanation: 说明:
git rm --cached
removes all csv files from index, leaving them on the disk; git rm --cached
从索引中删除所有csv文件,将它们留在磁盘上; unix2dos
as an example) unix2dos
为例) git add '*.csv'
adds them back, this time without any transformation, according to new version of .gitattributes git add '*.csv'
将它们添加回来,这次没有任何转换
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.