简体   繁体   English

带有CRLF和LF文件的Git存储库?

[英]Git repository with both CRLF and LF files?

I have a git repository whose files' line endings should be CRLF or LR on the checkedout depending on the specific file. 我有一个git存储库,其文件的行尾在结帐时应为CRLF或LR,具体取决于特定的文件。 For instance, I want that all *.sh files to be checked out with LR line endings while all *.bat files with CRLF. 例如,我希望检出所有* .sh文件带有LR行结尾,而所有* .bat文件检出带有CRLF。

I've been trying to pull this off with no results, next is my .gitattributes file: 我一直在尝试,没有结果,接下来是我的.gitattributes文件:

* text=auto
#
# Declare files that will always have CRLF line endings on checkout.
#

*.sh text eol=LF

#
# Declare files that will always have LF line endings on checkout.
#

*.bat text eol=CRLF

#
# Denote all files that are truly binary and should not be modified.
#

*.zip binary
*.tar binary
*.exe binary
*.dll binary
*/dropbear binary
*update-binary binary

When I open a .sh file or a .bat file both line endings are CRLF. 当我打开.sh文件或.bat文件时,两行结尾均为CRLF。 What am I doing wrong? 我究竟做错了什么?

Note: I develop on a Windows computer. 注意:我在Windows计算机上进行开发。

EDIT: System, global and local configuration 编辑:系统,全局和本地配置

System: 系统:

core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true

Global: 全球:

merge.tool=kdiff3
diff.guitool=kdiff3
core.editor="C:/Program Files (x86)/GitExtensions/GitExtensions.exe" fileeditor
core.autocrlf=true
credential.helper=!'C:\Users\XXXX\AppData\Roaming\GitCredStore\git-credential-winstore.exe'
user.name=xxxxx.xxxx
user.email=xxxx.xxxx@xxxxx.com
filter.lfs.clean=git-lfs clean %f
filter.lfs.smudge=git-lfs smudge %f
filter.lfs.required=true
push.default=matching

Local: 本地:

core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
remote.origin.url=https://github.com/XXXXXX/xxxxxx.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.v2.10.0.remote=origin
branch.v2.10.0.merge=refs/heads/v2.10.0
branch.v2.10.1.remote=origin
branch.v2.10.1.merge=refs/heads/v2.10.1

Also, GitHub's documentation states the following: 此外, GitHub的文档规定了以下内容:

Optionally, you can configure the way Git manages line endings on a per-repository basis by configuring a special .gitattributes file. (可选)您可以通过配置特殊的.gitattributes文件来配置Git在每个存储库的基础上管理行尾的方式。 This file is committed into the repository and overrides an individual's core.autocrlf setting, ensuring consistent behavior for all users, regardless of their Git settings. 该文件将提交到存储库中,并覆盖个人的core.autocrlf设置,从而确保所有用户的行为一致,无论其Git设置如何。

EDIT 2: 编辑2:

If I set core.autocrlf to false and comment all the lines of .gitattributes then both .sh and .bat files are opened with LF line endings. 如果将core.autocrlf设置为false并注释所有.gitattributes行,则.sh.bat文件都将以LF行结尾打开。

The eol attribute value, like most of Git, is case sensitive. 像大多数Git一样, eol属性值区分大小写。 You want: 你要:

*.sh eol=lf
*.bat eol=crlf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM