跨平臺的程式碼檔案,拉下來在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開啟了工程,或者是我在使用過程中開啟了這些原始碼檔案