使用gitattributes替换存储库行结尾
我曾尝试在共享存储库中规范行尾,该存储库包含windows和unix特定的文件,但我无法使它按预期的方式工作 我们都在Windows Box上开发,但要求行尾(取决于文件类型)为LF或CRLF。已建议开发人员将autocrlf设置为false,以便在存储库中不会更改某些需要CRLF的文件(存在windows和unix文件格式的混合),并在必要时手动更改行尾 有人建议,使用gitattributes可以在某种程度上减轻对应该使用哪些文件结尾进行监控的需要,但我一直无法让它正常工作 以下是我的用户git设置:使用gitattributes替换存储库行结尾,git,Git,我曾尝试在共享存储库中规范行尾,该存储库包含windows和unix特定的文件,但我无法使它按预期的方式工作 我们都在Windows Box上开发,但要求行尾(取决于文件类型)为LF或CRLF。已建议开发人员将autocrlf设置为false,以便在存储库中不会更改某些需要CRLF的文件(存在windows和unix文件格式的混合),并在必要时手动更改行尾 有人建议,使用gitattributes可以在某种程度上减轻对应该使用哪些文件结尾进行监控的需要,但我一直无法让它正常工作 以下是我的用户g
[core]
eol = native
bare = false
filemode = false
hideDotFiles = dotGitOnly
ignorecase = true
repositoryformatversion = 0
symlinks = false
autocrlf = true
editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession -noPlugin
[core]
fscache = true
[core]
logallrefupdates = true
programdata git设置:
[core]
eol = native
bare = false
filemode = false
hideDotFiles = dotGitOnly
ignorecase = true
repositoryformatversion = 0
symlinks = false
autocrlf = true
editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession -noPlugin
[core]
fscache = true
[core]
logallrefupdates = true
存储库git设置:
[core]
eol = native
bare = false
filemode = false
hideDotFiles = dotGitOnly
ignorecase = true
repositoryformatversion = 0
symlinks = false
autocrlf = true
editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession -noPlugin
[core]
fscache = true
[core]
logallrefupdates = true
.git属性文件:
# convert all to lf
* text eol=lf
# convert these to windows line endings
*.sbm text eol=crlf
*.sbp text eol=crlf
*.sin text eol=crlf
*.bat text eol=crlf
*.cmd text eol=crlf
*.ini text eol=crlf
*.inf text eol=crlf
/strataclient/BubbleHelp/* text eol=crlf
# don't touch binary files
*.dot binary
*.dll binary
*.exe binary
*.ocx binary
*.lic binary
*.cfn binary
为了测试它,我创建了一个小提交,其中包含.gittributes文件(我一直在修改该文件以测试不同的组合),然后运行以下命令:
git rm --cached -r .
git reset --hard
它似乎改变了一些行尾,但不是以我期待的方式
我试图遵循各种指南,但似乎没有一个能做出预期的深远改变。我希望所有文本文件都改为LF(如java、properties、txt),除非它是CRLF中列出的类型之一(如cmd、bat)。我偶然发现了这个问题,我很好奇2年多后这是否仍然是个问题 喂!在最新的Git版本中,提交.gittributes文件后,只需执行一个
Git添加--renormalize
,如下所述: