threads / discuss / 60613

End-of-line comments are prompted with "is not a valid attribute name"

Subject: End-of-line comments are prompted with "is not a valid attribute name"

## tl;dr

4 messages between Dec 13, 2023 and Dec 17, 2023.

replies: 3people: 2as markdown or json

D无数· Dec 13, 2023, 17:32 UTC · lore
> macos 13.5.2
> git version 2.37.0 (Apple Git-136)

I use end-of-line comments in my .gitattributes file, and it is often (not always present, but often) prompted with '# is not a valid attribute name: .gitattributes:1' when performing many operations.

This is my .gitattributes: ``` res/csv/*.txt eol=lf # 保证csv为lf,以匹配解析格式

# Custom for Visual Studio *.cs diff=csharp ```

When performing certain operations: ···shell

> git status

# is not a valid attribute name: .gitattributes:1 On branch master Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean ···

Other repositories that have .gitattributes files and include end-of-line comments do the same thing. I'm sure there are no special characters in my files.

Junio C Hamano· Dec 13, 2023, 19:22 UTC · re: D无数 · lore

Re: End-of-line comments are prompted with "is not a valid attribute name"

D无数 <wushuripple@gmail.com> writes:
> This is my .gitattributes:
> ```
> res/csv/*.txt eol=lf # 保证csv为lf,以匹配解析格式

I do not think of any version of Git ignoring what you wrote after # (including #) in the middle of the line.

> # Custom for Visual Studio
I know I designed the parser to allow this as a comment, though.
So
> When performing certain operations:
> ···shell
>> git status
> # is not a valid attribute name: .gitattributes:1
This is totally expected; nothing to see here.
Junio C Hamano· Dec 17, 2023, 17:15 UTC · re: Junio C Hamano · lore

Re: End-of-line comments are prompted with "is not a valid attribute name"

Junio C Hamano <gitster@pobox.com> writes:
> This is totally expected; nothing to see here.

To put it another way, we do not have "end-of-line comment" (i.e. the leading part of a line has payload, but the line is chomped in the middle with a comment character and the remainder of the line is ignored) at all. We have "commented line" (in other words, a line that is totally commented out and gets ignored).

I think it is very clearly documented in "git help attributes":
    A `gitattributes` file is a simple text file that gives
    `attributes` to pathnames.
    Each line in `gitattributes` file is of form:
            pattern attr1 attr2 ...
    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.
D无数· Dec 17, 2023, 17:28 UTC · re: Junio C Hamano · lore

Re: End-of-line comments are prompted with "is not a valid attribute name"

I see, thanks for the answer. I was fooled by the VSCode highlighting, but also because I didn't try to figure out the documentation carefully.

Junio C Hamano <gitster@pobox.com> 于2023年12月18日周一 01:15写道:
Show 25 quoted lines
>
> Junio C Hamano <gitster@pobox.com> writes:
>
> > This is totally expected; nothing to see here.
>
> To put it another way, we do not have "end-of-line comment"
> (i.e. the leading part of a line has payload, but the line is
> chomped in the middle with a comment character and the remainder of
> the line is ignored) at all.  We have "commented line" (in other
> words, a line that is totally commented out and gets ignored).
>
> I think it is very clearly documented in "git help attributes":
>
>     A `gitattributes` file is a simple text file that gives
>     `attributes` to pathnames.
>
>     Each line in `gitattributes` file is of form:
>
>             pattern attr1 attr2 ...
>
>     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.
>

← back to recent threads