svn和git提交时忽略不同平台的换行符(unix-eol)

跨平台的代码文件,拉下来在windows上没有修改,使用vs打开工程后就会有大量文件出现在修改列表中,对比diff,差异在最后一行分别是windowx的换行和unix的换行,也就是不同平台的换行符不一样,那么如何让svn忽略这种差异呢?

svn忽略不同平台的换行符

首先找到SVN配置文件:

进入项目的svn目录,tortoisesvn - 右键 - settings - general - edit,会打开全局的config文件,或者打开 %APPDATA%\Roaming\Subversion\config

找到[miscellany]选项下的enable-auto-props,去掉注释后值为enable-auto-props = yes
然后在[auto-props]一节添加或修改文件类型

[auto-props]
*.sample = svn:eol-style=native
*.json = svn:eol-style=native
*.script = svn:eol-style=native
*.txt = svn:eol-style=native
*.py = svn:eol-style=native
*.gitignore = svn:eol-style=native
*.yaml = svn:eol-style=native
*.bat = svn:eol-style=native
*.ini = svn:eol-style=native
*.xml = svn:eol-style=native
*.csd = svn:eol-style=native
*.ccs = svn:eol-style=native
*.cfg = svn:eol-style=native
*.udf = svn:eol-style=native
*.lua = svn:eol-style=native
*.pbxproj = svn:eol-style=native
*.vcxproj = svn:eol-style=native
*.mk = svn:eol-style=native
*.filters = svn:eol-style=native
*.sh = svn:eol-style=native
*.project = svn:eol-style=native
*.classpath = svn:eol-style=native
*.properties = svn:eol-style=native
*.java = svn:eol-style=native
*.mm = svn:eol-style=native
*.pch = svn:eol-style=native
*.xib = svn:eol-style=native
*.plist = svn:eol-style=native
*.strings = svn:eol-style=native
*.pbxproj = svn:eol-style=native
*.c = svn:eol-style=native
*.cpp = svn:eol-style=native
*.h = svn:keywords=Author Date Id Rev URL;svn:eol-style=native

这样以后commit的新文件的end of line属性将被指定为native,不同的系统下再获取该文件时会自动转换为相应的回车换行方式。

附完整的代码类型:apache.org/dev/svn-eol-style.txt

已在svn或已提交的文件

在修改列表批量选中文件,右键 - properties - New - EOL,选择native,注意要选中文件而不是文件夹

然后再把修改后进行commit即可,diff时看到最后添加了一行native,但用文本打开查看并无差异

git忽略不同平台的换行符

打开.gitignore文件,添加以下行

# 忽略行末空格
*.* trailing-space

差异是如何产生的?

应该是我使用vs打开了工程,或者是我在使用过程中打开了这些源代码文件

posted @ 2024-06-03 22:50  赵青青  阅读(47)  评论(0编辑  收藏  举报