英文:
What are valid attribute names in git? (What is the syntax of git attribute names?)
问题
I've been placing in my .gitattributes
the following:
.htaccess merge = ours
Then Git was showing an error about "not a valid attribute name".
What I have tried then:
.htaccess merge=ours
Or to write that out: If you've setting an attribute value, but you've put spaces around the equals sign, then just remove the spaces. It's not only me.
(cf. STEGRIFF BLOG "GITATTRIBUTES ERROR ‘ IS NOT A VALID ATTRIBUTE NAME’" Written 2015-09-29)
But now, apart from that they do not can contain spaces, what are valid attribute names in Git since that date back at then end 2015?
The error message was not telling me for today and my text-generation skills are weak so I could not probe whole Unicode (and the undocumented encodings Git may support) against my local git version and then I don't know which other git versions everyone else is going to use that will checkout the repository.
So back until 2015 looks pretty OK-ish for an answer to me 2023. As this is a question about git, I'd guess there is a grep query that can tell me that, but, uhmm, I feel weak today. Any help much appreciated.
英文:
A quick story what happended: I've been placing in my .gitattributes
the following:
.htaccess merge = ours
Then Git was showing an error about "not a valid attribute name".
What I have tried then:
.htaccess merge=ours
Or to write that out: If you've setting an attribute value, but you’ve put spaces around the equals sign, then just remove the spaces. It's not only me.
(cf. STEGRIFF BLOG "GITATTRIBUTES ERROR ‘ IS NOT A VALID ATTRIBUTE NAME’" Written 2015-09-29)
But now, apart from that they do not can contain spaces, what are valid attribute names in Git since that date back at then end 2015?
The error message was not telling me for today and my text-generation skills are weak so I could not probe whole Unicode (and the undocumented encodings Git may support) against my local git version and then I don't know which other git versions everyone else is going to use that will checkout the repository.
So back until 2015 looks pretty OK-ish for an answer to me 2023. As this is a question about git, I'd guess there is a grep query that can tell me that, but, uhmm, I feel weak today. Any help much appreceated.
答案1
得分: 2
`gitattributes(5)`文档对每行的格式有以下描述:
> 即,由模式后跟属性列表组成,用空格分隔。前导和尾随空格将被忽略。以#开头的行将被忽略。以双引号开头的模式将以C样式引用。
文档没有描述属性名称,但代码中有(`attr.c`中的`attr_name_valid`函数),其中包括以下文本:
> 属性名称不能以“-”开头,必须由字符`[-A-Za-z0-9_.]`组成。
属性的主体部分(如果有的话)似乎没有受到限制,但我强烈建议您坚持使用UTF-8。没有人愿意在文件中有任意的字节序列。
请注意,由于您在属性周围指定了空格,您尝试定义了三个独立的属性:`merge`,`=`和`ours`。由于`=`不是有效的属性,您收到了错误消息。
英文:
The gitattributes(5)
documentation says this about the format of each line:
> That is, a pattern followed by an attributes list, separated by whitespaces. Leading and trailing whitespaces are ignored. Lines that begin with # are ignored. Patterns that begin with a double quote are quoted in C style.
The documentation doesn't describe attribute names, but the code does (function attr_name_valid
in attr.c
), with this text:
> Attribute name cannot begin with -
and must consist of characters from [-A-Za-z0-9_.]
.
The body of the attribute, if any, doesn't seem to be restricted, but I'd strongly encourage you to stick to UTF-8. Nobody will be happy to have arbitrary byte sequences in the file.
Note that because you specified spaces around the attribute, you tried to define three separate attributes: merge
, =
, and ours
. Since =
is not a valid attribute, you got that error message.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论